2

I'm trying to write some python code to download an excel file, given a direct link. The link is a sharepoint direct download link. I'm getting a 404 unauthorized error when running the code, which I know is because I need to somehow correctly put in the username and password for the sharepoint.

My code snippet looks like this:

username = 'abc'
password = '123'
url = 'http://example.com/spreadsheet.xls'
r = requests.get(url, auth=HTTPBasicAuth(username, password))
print(r)
# <Response [401]>

I haven't even gotten to the downloading portion if I can't get the authentication right. If the code works, I should expect the value of r to be 200, but I get the value 401, which is an unauthorized error. I'm sure that my username and password are both correct.

Any help would be appreciated. Thanks!

1 Answer 1

1

The authentication you are using could be wrong. Replace HTTPBasicAuth with NTLM auth or HttpNegotiateAuth.

from requests_ntlm import HttpNtlmAuth, HttpNtlmSspiAuth
auth = HttpNtlmSspiAuth()

from requests_negotiate_sspi import HttpNegotiateAuth
auth = HttpNegotiateAuth()
Sign up to request clarification or add additional context in comments.

Comments

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.