I want to login to a website and want to download some files from there afterwards. After some research I thought that using requests will do the trick. I've tried several approaches mentioned on SO and other sites but the result is always the same. After I successfully log in with requests.post() and want to download a file with requests.get(), I keep getting the 401 Authenticication Error. The targeted urls are:
url_login = 'https://scihub.copernicus.eu/dhus/#/home'
url_data = 'https://scihub.copernicus.eu/dhus/odata/v1/Products(\'09f4711b-05da-421c-9090-47b563ca75e9\')/$value'
Here's what I've tried:
#1
import requests
from requests.auth import HTTPDigestAuth
req = requests.get(url_login, auth=HTTPDigestAuth('user', 'password'))
print(req.status_code) # gets HTML code 200
data = requests.get(url_data)
print(data.status_code) # gets HTML code 401
#2
import requests
credentials = dict(login='user', password='password')
session = requests.Session()
req = session.post(url_login, data=credentials)
print(req.status_code) # gets HTML code 200
data = session.get(url_data)
print(data.status_code) # gets HTML code 401
#3
import requests
from requests.auth import HTTPBasicAuth
session = requests.Session()
req = session.get(url_login, auth=(HTTPBasicAuth('user', 'password')))
print(req.status_code) # gets HTML code 200
data = session.get(url_data)
print(data.status_code) # gets HTML code 401
What am I missing here? I'm using Python 3.8 in an Conda environment.