1

I'm trying to download a zip file from a provider, using wget works fine:

wget -c --http-user=MY_UN --http-password=MY_PW "https://datapool.asf.alaska.edu/GRD_MD/SA/S1A_EW_GRDM_1SDH_20151003T040339_20151003T040351_007983_00B2A6_7377.zip"

However using the Python Requests library I get 401 errors using the same credentials, does anybody know why that might be, or where to look to begin understanding the problem?

url = "https://datapool.asf.alaska.edu/GRD_MD/SA/S1A_EW_GRDM_1SDH_20151003T040339_20151003T040351_007983_00B2A6_7377.zip"    
r = requests.get(url, auth=("MY_UN", "MY_PW"), stream = True)

I should mention that I have quadruple checked the details, and they are correct on both. Is there an alternative method in Python?

In the mean time I have had to spawn a wget using the os package:

os.system("wget -c --http-user=MY_UN--http-password=MY_PW 'https://datapool.asf.alaska.edu/GRD_MD/SA/S1A_EW_GRDM_1SDH_20151003T040339_20151003T040351_007983_00B2A6_7377.zip'")
4
  • does your password contains backslashes? you could try to pass the r prefix to your string. Commented Nov 7, 2016 at 12:26
  • No I'm afraid not, just characters and numbers, same for my user name, except that the UN has a . in it. Good idea though, are you thinking of escaping the string? Commented Nov 7, 2016 at 12:27
  • It looks like they are doing oauth. This might help? stackoverflow.com/questions/12397375/… Commented Nov 7, 2016 at 15:00
  • With requests, your example is explicitly trying to authenticate with HTTP Basic Authentication. However, wget supports multiple types of authentication when passing http-user/--http-password. It is likely your app is using a different type like Digest or NTLM. That would explain why your example in wget works while requests failed. The docs for requests have examples for different authentication here: 2.python-requests.org/en/master/user/authentication Commented Aug 16, 2019 at 18:51

2 Answers 2

2

I got a similar issue, I solved it using an HTTPDigestAuth instead of an HTTPBasicAuth.

from requests.auth import HTTPDigestAuth
requests.get(url, auth=HTTPDigestAuth('mylogin', 'mypassword'))
Sign up to request clarification or add additional context in comments.

Comments

0

I would suggest to try the following:

session = requests.Session()
session.trust_env = False # to bypass a proxy
r = session.get(url, verify=False) # or if there is a certificate do verify='file.cer'

1 Comment

Try to put login and password into variables and print them out to see if they still look the same

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.