复制curl在Python中协商连接(使用kerberos auth)

时间:2018-04-20 19:07:12

标签: python curl python-requests kerberos

我想在Python中复制以下curl命令。

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

我在这里跟踪了这个pycurl示例,它工作正常 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()

有没有办法用Python请求模块做到这一点?

谢谢!

1 个答案:

答案 0 :(得分:0)

您可以尝试以下项目:https://pypi.org/project/requests-negotiate/,或者如果您使用的是Kerberos:https://pypi.org/project/requests-kerberos/

使用任一方法,您的代码将如下所示:

auth = HTTPNegotiateAuth()  # or: HTTPKerberosAuth()
response = requests.get('https://example.com/authenticate', auth=auth, verify=False)