Spaces:
Running
Running
handle ip location lookup error
Browse files- check_proxy.py +6 -2
check_proxy.py
CHANGED
@@ -6,8 +6,11 @@ def check_proxy(proxies):
|
|
6 |
response = requests.get("https://ipapi.co/json/", proxies=proxies, timeout=4)
|
7 |
data = response.json()
|
8 |
print(f'查询代理的地理位置,返回的结果是{data}')
|
9 |
-
|
10 |
-
|
|
|
|
|
|
|
11 |
print(result)
|
12 |
return result
|
13 |
except:
|
@@ -17,6 +20,7 @@ def check_proxy(proxies):
|
|
17 |
|
18 |
|
19 |
if __name__ == '__main__':
|
|
|
20 |
try: from config_private import proxies # 放自己的秘密如API和代理网址 os.path.exists('config_private.py')
|
21 |
except: from config import proxies
|
22 |
check_proxy(proxies)
|
|
|
6 |
response = requests.get("https://ipapi.co/json/", proxies=proxies, timeout=4)
|
7 |
data = response.json()
|
8 |
print(f'查询代理的地理位置,返回的结果是{data}')
|
9 |
+
if 'country_name' in data:
|
10 |
+
country = data['country_name']
|
11 |
+
result = f"代理配置 {proxies_https}, 代理所在地:{country}"
|
12 |
+
elif 'error' in data:
|
13 |
+
result = f"代理配置 {proxies_https}, 代理所在地:未知,IP查询频率受限"
|
14 |
print(result)
|
15 |
return result
|
16 |
except:
|
|
|
20 |
|
21 |
|
22 |
if __name__ == '__main__':
|
23 |
+
import os; os.environ['no_proxy'] = '*' # 避免代理网络产生意外污染
|
24 |
try: from config_private import proxies # 放自己的秘密如API和代理网址 os.path.exists('config_private.py')
|
25 |
except: from config import proxies
|
26 |
check_proxy(proxies)
|