Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Replicate curl negotiate connection (using kerberos auth) in Python

I'd like to replicate the following curl command in Python.

curl -u : --negotiate -k https://example.com/authenticate

I followed this pycurl example here and it worked fine http://www.deplication.net/2014/02/curl-with-kerberos-authentication.html

curl = pycurl.Curl()
curl.setopt(pycurl.HTTPAUTH, pycurl.HTTPAUTH_GSSNEGOTIATE)
curl.setopt(pycurl.USERPWD, ':')
curl.setopt(pycurl.URL, 'https://example.com/authenticate'
curl.perform()

Is there a way to do it with Python requests module?

Thanks!!

like image 981
abisko Avatar asked Apr 20 '18 19:04

abisko


1 Answers

You can try this project: https://pypi.org/project/requests-negotiate/, or if you're using Kerberos: https://pypi.org/project/requests-kerberos/

With either, your code will look something like this:

auth = HTTPNegotiateAuth()  # or: HTTPKerberosAuth()
response = requests.get('https://example.com/authenticate', auth=auth, verify=False)
like image 150
gnvk Avatar answered Oct 03 '22 14:10

gnvk