Update app.py
Browse files
app.py
CHANGED
@@ -26,20 +26,22 @@ async def fetch_url(url, session, max_retries=3):
|
|
26 |
|
27 |
async def extract_and_transform_proxies(input_text):
|
28 |
try:
|
|
|
29 |
data = yaml.safe_load(input_text)
|
30 |
if isinstance(data, dict) and 'proxies' in data:
|
31 |
proxies_list = data['proxies']
|
32 |
elif isinstance(data, list):
|
33 |
proxies_list = data
|
34 |
else:
|
35 |
-
|
|
|
36 |
if proxies_match:
|
37 |
proxies_text = proxies_match.group(1)
|
38 |
proxies_list = yaml.safe_load(proxies_text)
|
39 |
else:
|
40 |
return "未找到有效的代理配置"
|
41 |
-
except yaml.YAMLError:
|
42 |
-
return "YAML
|
43 |
|
44 |
if not proxies_list:
|
45 |
return "未找到有效的代理配置"
|
|
|
26 |
|
27 |
async def extract_and_transform_proxies(input_text):
|
28 |
try:
|
29 |
+
# 尝试直接解析整个输入作为YAML
|
30 |
data = yaml.safe_load(input_text)
|
31 |
if isinstance(data, dict) and 'proxies' in data:
|
32 |
proxies_list = data['proxies']
|
33 |
elif isinstance(data, list):
|
34 |
proxies_list = data
|
35 |
else:
|
36 |
+
# 如果不是预期的格式,尝试提取proxies部分
|
37 |
+
proxies_match = re.search(r'proxies:\s*\n((?:[-\s]*{.*\n?)*)', input_text, re.MULTILINE | re.DOTALL)
|
38 |
if proxies_match:
|
39 |
proxies_text = proxies_match.group(1)
|
40 |
proxies_list = yaml.safe_load(proxies_text)
|
41 |
else:
|
42 |
return "未找到有效的代理配置"
|
43 |
+
except yaml.YAMLError as e:
|
44 |
+
return f"YAML解析错误: {str(e)}"
|
45 |
|
46 |
if not proxies_list:
|
47 |
return "未找到有效的代理配置"
|