I'm trying to download files from a website that uses HttpBasicAuth. Everything worked fine on an Ubuntu machine but not when I tried to run my script on a Windows machine. I have problems downloading files from that website using requests. Below is the code relevant to my problem:
Initial code that works on Ubuntu:
url = 'https://abc.example.com'
s = requests.Session()
s.verify = False
s.auth = (creds['user'], creds['passwd'])
filename = "somefile.txt"
download_url = url + "/" + filename
resp = s.get(download_url) # fails on this line when run in Windows
I did a verify=False
because I'm having SSL3_GET_SERVER_CERTIFICATE:certificate verify failed.
if I don't. I don't understand fully what that means and I would appreciate an explanation. From how I understood it, requests just cannot verify the server's cert. Similarly, it seemed that my browser does not recognize the certificate either as seen below.
Anyways, so I ran the script on Windows that has pretty much the same python version (2.7.x) and I got this:
I did a quick search and found some fixes here and found a github issue here. I followed the first fix and changed my code to:
url = 'https://abc.example.com'
s = requests.Session()
s.verify = False
s.auth = (creds['user'], creds['passwd'])
s.mount('https://', MyAdapter())
# .. omitted code similar to the one above ..
resp = s.get(download_url)
I added the class specified in the answer
class MyAdapter(HTTPAdapter):
def init_poolmanager(self, connections, maxsize, block=False):
self.poolmanager = PoolManager(num_pools=connections,
maxsize=maxsize,
block=block,
ssl_version=ssl.PROTOCOL_TLSv1)
It is still showing the same errors.
From the github issue, they were checking the OpenSSL version, so I did a check on the Windows machine and if I remember correctly it is 1.0.2a
. I did a check on the Ubuntu machine where the initial version was working, it is 1.0.1f
.
EDIT:
Python version in Ubuntu: 2.7.6 (works here)
Python version in Windows: 2.7.10 (does not work here)