Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Handling windows authentication while accessing url using requests

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?

like image 551
Srikanth Avatar asked Aug 31 '15 06:08

Srikanth


People also ask

How does Windows domain authentication work?

Here's how the authentication process goes:The client requests an authentication ticket from the AD server. The AD server returns the ticket to the client. The client sends this ticket to the Endpoint Server. The Server then returns an acknowledgment of authentication to the client.

Which method can be used for authentication in Windows 10 operating system?

The Windows operating system implements a default set of authentication protocols, including Kerberos, NTLM, Transport Layer Security/Secure Sockets Layer (TLS/SSL), and Digest, as part of an extensible architecture.

How do you authenticate using Python requests?

To achieve this authentication, typically one provides authentication data through Authorization header or a custom header defined by server. Replace “user” and “pass” with your username and password. It will authenticate the request and return a response 200 or else it will return error 403.


1 Answers

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'))
like image 115
ρss Avatar answered Oct 20 '22 05:10

ρss