【发布时间】:2020-07-26 12:56:30
【问题描述】:
我在127.0.0.1:8080 有一个本地代理服务
我可以用它进行 api 调用,但不能在 django 中,由于某种原因,它可以在常规 python 代码(即python test.py)中工作,但不能在 django 中。
import requests
proxies = {
'http': 'http://127.0.0.1:8080',
'https': 'https://127.0.0.1:8080',
}
response = requests.get('https://api.ipify.org?format=json', proxies=proxies)
django v3.0.8 和请求 v2.24.0
我假设 WSGI 以某种方式覆盖了我的代理设置
错误
HTTPSConnectionPool(host='api.ipify.org', port=443): Max retries exceeded with url: /?format=json (Caused by ProxyError('Cannot connect to proxy.', NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x7fa922093340>: Failed to establish a new connection: [Errno 111] Connection refused')))
【问题讨论】:
标签: python django python-requests wsgi