Commit 0e513c76 by baiquan

refactor(utils): 重构代理验证逻辑并优化抖店服务接口调用

- 重构了 check_proxy 函数,移除了代理验证逻辑,现在直接返回代理配置
- 优化了 doudian_service.py 中的商品创建接口调用,增加了对返回数据的处理
- 添加了成功和失败日志记录,提高了错误处理的可读性
parent ccb903a4
......@@ -81,7 +81,14 @@ def create_goods(headers: dict, proxy_url: str, data):
try:
response = requests.post(url, params=params, proxies=proxies, json=data, headers=headers)
if response.status_code == 200:
return response.json()
res_data = response.json()
if res_data['code'] == 0:
res_data['code'] = 200
logger.info(f"商品创建成功 --> {res_data}")
else:
logger.error(f"商品创建失败 --> {res_data}")
logger.info(f"data --> {data}")
return res_data
else:
raise Exception(f'请求失败 --> {response.text}')
except Exception as e:
......
......@@ -16,21 +16,23 @@ DEFAULT_HEADER = {
}
# 检查代理
def check_proxy(proxy_url):
if not proxy_url:
raise ProxyConnectionError(f"缺少代理")
proxies = {
"http": proxy_url,
"https": proxy_url
}
# return proxies
addr = urlparse(proxy_url).hostname
try:
test_res = requests.get('http://httpbin.org/ip', timeout=10, proxies=proxies).json()
except Exception as e:
raise ProxyConnectionError(f"{addr}-->代理验证失败-->{str(e)}")
if test_res.get('origin', "") == addr:
logger.debug(f"{addr}-->代理验证成功")
return proxies
else:
raise ProxyConnectionError(f"{addr}-->代理验证失败")
# addr = urlparse(proxy_url).hostname
# try:
# test_res = requests.get('http://httpbin.org/ip', timeout=10, proxies=proxies).json()
# except Exception as e:
# raise ProxyConnectionError(f"{addr}-->代理验证失败-->{str(e)}")
# if test_res.get('origin', "") == addr:
# logger.debug(f"{addr}-->代理验证成功")
# return proxies
# else:
# raise ProxyConnectionError(f"{addr}-->代理验证失败")
def encryptParamsId(login_subject_uid, user_identity_id):
e = {
......
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