【发布时间】:2020-11-12 01:02:42
【问题描述】:
我正在尝试使用 PyCharm 的请求功能。
import requests
url = 'https://www.google.com'
ProxyDict = {"http_proxy":"http://proxy-us.MyCompany.com:911","https_proxy":"http://proxy-us.MyCompany.com:912"}
o = requests.get(url,proxies = ProxyDict)
print(o.status_code)
它给了我
requests.exceptions.ConnectionError: HTTPSConnectionPool(host='www.google.com', port=443): Max retries exceeded with url: / (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x0000027CBF508B00>: Failed to establish a new connection: [WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond',))
但是当我尝试从 cmd 运行以下命令时,它起作用了。
$set http_proxy=http://proxy-us.MyCompany.com:911
$set https_proxy=http://proxy-us.MyCompany.com:912
$ python ip_locator.py
200
我尝试了以下操作:
- 设置名为 HTTP_PROXY 和 HTTPS_PROXY 的系统环境变量
- 在Pycharm中,Ctrl+Alt+S --> HTTP Proxy -> 自动代理配置 URL:http://proxy-us.MyCompany.com:911
但是我的方法都没有成功在 PyCharm 中设置代理。有什么建议吗?
【问题讨论】:
标签: python proxy python-requests pycharm