自然语言搜索去掉代理
This commit is contained in:
parent
94b82723fa
commit
d8917d96c0
@ -618,11 +618,25 @@ class CreatorDiscoveryViewSet(viewsets.ReadOnlyModelViewSet):
|
|||||||
import requests
|
import requests
|
||||||
import logging
|
import logging
|
||||||
import json
|
import json
|
||||||
|
import os
|
||||||
from apps.daren_detail.models import CreatorProfile
|
from apps.daren_detail.models import CreatorProfile
|
||||||
from apps.user.models import User
|
from apps.user.models import User
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
# 清除环境变量中的代理设置
|
||||||
|
os_environ_copy = os.environ.copy()
|
||||||
|
if 'HTTP_PROXY' in os.environ:
|
||||||
|
del os.environ['HTTP_PROXY']
|
||||||
|
if 'HTTPS_PROXY' in os.environ:
|
||||||
|
del os.environ['HTTPS_PROXY']
|
||||||
|
if 'http_proxy' in os.environ:
|
||||||
|
del os.environ['http_proxy']
|
||||||
|
if 'https_proxy' in os.environ:
|
||||||
|
del os.environ['https_proxy']
|
||||||
|
|
||||||
|
logger.info("已清除代理环境变量")
|
||||||
|
|
||||||
# 调用外部API
|
# 调用外部API
|
||||||
api_url = 'http://81.69.223.133:58099/api/operation/sql_search/'
|
api_url = 'http://81.69.223.133:58099/api/operation/sql_search/'
|
||||||
headers = {
|
headers = {
|
||||||
@ -636,14 +650,21 @@ class CreatorDiscoveryViewSet(viewsets.ReadOnlyModelViewSet):
|
|||||||
|
|
||||||
logger.info(f"调用外部API,参数: {payload}")
|
logger.info(f"调用外部API,参数: {payload}")
|
||||||
|
|
||||||
# 发送请求
|
# 创建一个没有代理的会话
|
||||||
response = requests.post(api_url, headers=headers, json=payload)
|
session = requests.Session()
|
||||||
|
session.proxies.clear()
|
||||||
|
|
||||||
|
# 发送请求,禁用代理
|
||||||
|
response = session.post(api_url, headers=headers, json=payload)
|
||||||
|
|
||||||
# 检查请求是否成功
|
# 检查请求是否成功
|
||||||
if response.status_code != 200:
|
if response.status_code != 200:
|
||||||
logger.error(f"外部API请求失败,状态码: {response.status_code}, 响应: {response.text}")
|
logger.error(f"外部API请求失败,状态码: {response.status_code}, 响应: {response.text}")
|
||||||
return ApiResponse.error(f"外部API请求失败,状态码: {response.status_code}", code=500)
|
return ApiResponse.error(f"外部API请求失败,状态码: {response.status_code}", code=500)
|
||||||
|
|
||||||
|
# 恢复环境变量
|
||||||
|
os.environ.update(os_environ_copy)
|
||||||
|
|
||||||
# 解析响应
|
# 解析响应
|
||||||
resp_data = response.json()
|
resp_data = response.json()
|
||||||
logger.info(f"外部API响应成功: {resp_data}")
|
logger.info(f"外部API响应成功: {resp_data}")
|
||||||
|
Loading…
Reference in New Issue
Block a user