I am working in a corporate environment with a proxy (with user/passs). I use PyCharm on a Windows machine and Python 3.6.
Based on this post: How to pass all Python's traffics through a http proxy? I managed to write my python script that connects to the web.
Unfortunately I had to reinstall Pycharm and create a new python project. Now I run the same script that connects to the web but receive the following error message (simply trying to connect to 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)'),))
This is my code:
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)
If I change the line
r = requests.get('https://www.google.com')
to this:
r = requests.get('https://www.google.com', verify=False)
it works but I receive the warning:
InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised.
Executing the code on another machine without proxy This issue doesn't appear at all.
I added google's certificate in PyCharm's settings (Settings -> Tools -> Server Certificates) and selected "Accept non-trusted certificates automatically". But nothing changes, same error messages.
Is there any further settings I can do in PyCharm/Python to solve that issue?