Commit 334804f0 by baiquan

添加代理异常类

parent f901d7c0
...@@ -3,10 +3,12 @@ import random ...@@ -3,10 +3,12 @@ import random
import time import time
from hashlib import md5 from hashlib import md5
from urllib.parse import urlparse from urllib.parse import urlparse
import requests import requests
from utils.errors import AppError
from loguru import logger from loguru import logger
from utils.errors import ProxyConnectionError
# 检查代理 # 检查代理
def check_proxy(proxy_url): def check_proxy(proxy_url):
...@@ -18,12 +20,12 @@ def check_proxy(proxy_url): ...@@ -18,12 +20,12 @@ def check_proxy(proxy_url):
try: try:
test_res = requests.get('http://httpbin.org/ip', timeout=10, proxies=proxies).json() test_res = requests.get('http://httpbin.org/ip', timeout=10, proxies=proxies).json()
except Exception as e: except Exception as e:
raise AppError(f"{addr}-->代理验证失败-->{str(e)}") raise ProxyConnectionError(f"{addr}-->代理验证失败-->{str(e)}")
if test_res.get('origin', "") == addr: if test_res.get('origin', "") == addr:
logger.info(f"{addr}-->代理验证成功") logger.info(f"{addr}-->代理验证成功")
return proxies return proxies
else: else:
raise AppError(f"{addr}-->代理验证失败") raise ProxyConnectionError(f"{addr}-->代理验证失败")
def encryptParamsId(login_subject_uid, user_identity_id): def encryptParamsId(login_subject_uid, user_identity_id):
e = { e = {
......
...@@ -28,4 +28,9 @@ class ABogusParamsError(AppError): ...@@ -28,4 +28,9 @@ class ABogusParamsError(AppError):
class CookiesExpiredError(AppError): class CookiesExpiredError(AppError):
"""cookies过期异常""" """cookies过期异常"""
def __init__(self, msg='cookies过期', data=None): def __init__(self, msg='cookies过期', data=None):
super().__init__(code=402, msg=msg, data=data) super().__init__(code=402, msg=msg, data=data)
\ No newline at end of file
class ProxyConnectionError(AppError):
"""代理连接失败异常"""
def __init__(self, msg='代理连接失败', data=None):
super().__init__(code=403, msg=msg, data=data)
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment