Handling windows authentication while accessing url using requests

Srikanth picture Srikanth · Aug 31, 2015 · Viewed 22.3k times · Source

I am using python request library to access the soap requests. And it was working fine. As there is change in our domain structure. I could not access the url, it always prompting me to enter the credentials.

enter image description here

I am using below code to access the url earlier using requests.

program_list_response = requests.get(program_list_path,
                                                 data=self.body, headers=self.headers)

How to pass the authentication in background using requests?

Answer

ρss picture ρss · Aug 31, 2015

You can use the Authentication feature for that in order to provide the credentials for the link that you want to access.

For an eg:

You can pass the username and password by using the below format:

requests.get('https://website.com/user', auth=('user', 'pass'))

For more details I would recommend the official docs.

For handling the Windows authentication then I would recommend the Requests-NTLM.

For eg:

import requests
from requests_ntlm import HttpNtlmAuth

requests.get("http://ntlm_protected_site.com",auth=HttpNtlmAuth('domain\\username','password'))