使用PyCharm

时间:2018-01-25 15:25:18

标签: python proxy pycharm global

我在公司环境中使用代理(使用用户/通行证)。我在Windows机器和Python 3.6上使用PyCharm。

基于这篇文章: How to pass all Python's traffics through a http proxy?我设法写了连接到网络的python脚本。

不幸的是我不得不重新安装Pycharm并创建一个新的python项目。现在我运行连接到网络的相同脚本,但收到以下错误消息(只是尝试连接到google.com):

requests.exceptions.SSLError: HTTPSConnectionPool(host='www.google.com', port=443): Max retries exceeded with url: / (Caused by SSLError(SSLError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:777)'),))

这是我的代码:

import os

proxy = 'http://user:password@proxyname:port'
os.environ['http_proxy'] = proxy
os.environ['HTTP_PROXY'] = proxy
os.environ['https_proxy'] = proxy
os.environ['HTTPS_PROXY'] = proxy

import requests
r = requests.get('https://www.google.com')
print(r.text)

如果我改变了行

r = requests.get('https://www.google.com')

到此:

r = requests.get('https://www.google.com', verify=False)

它有效,但我收到警告:

InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised.

在没有代理的情况下在另一台机器上执行代码此问题根本没有出现。

我在PyCharm的设置中添加了google的证书(设置 - >工具 - >服务器证书)并选择了“自动接受不受信任的证书”。但没有任何变化,相同的错误信息。

我可以在PyCharm / Python中做任何进一步的设置来解决这个问题吗?

0 个答案:

没有答案