繁体   English   中英

使用Python request_kerberos的API连接

[英]API Connection using Python requests_kerberos

这是我第一次尝试使用Kerberos身份验证通过python(从Windows)连接到API的经验。 我已经为此工作了几天,但进度一直停滞不前。 以下是我一直在使用的一些参考资料:

这是我找到的最好的教程,但似乎使用的是不推荐使用的模块,而不是requests_kerberos: http : //python-notes.curiousefficiency.org/en/latest/python_kerberos.html

https://pypi.org/project/requests-kerberos/

https://programtalk.com/python-examples/requests_kerberos.HTTPKerberosAuth/

到目前为止,这是我尝试过的操作(我将屏蔽敏感信息):

import requests
from requests_kerberos import HTTPKerberosAuth
r=requests.get("https://apiServer.hadoop.company.com:23232/templeton/v1/ddl/database/",auth=HTTPSKerberosAuth)

这是一些输出:

r.status_code

401

r.headers

{'Content-Length':'1321','Set-Cookie':'hadoop.auth =; 路径= /; HttpOnly','Server':'Jetty(7.6.0.v20120127)','Cache-Control':'必须重新验证,no-cache,no-store','Content-Type':'text / html; charset = ISO-8859-1”,“ WWW-Authenticate”:“协商”}

r.text

<html>\n<head>\n<meta http-equiv="Content-Type" 
content="text/html;charset=ISO
-8859-1"/>\n<title>Error 401 Authentication 
required</title>\n</head>\n<body>\n<
h2>HTTP ERROR: 401</h2>\n<p>Problem accessing /templeton/v1/ddl/database/. 
Reason:\n<pre>    Authentication required</pre></p>\n<hr /><i><small>Powered 
by Jetty://</small></i>

此输出是否至少表明服务器正在接收我的请求?

如果我使用curl从我们的Linux环境连接到API,它就可以正常工作,并且我会收到预期的输出:

curl --negotiate -i -u :  'http://apiServer.hadoop.company.com:23232/templeton/v1/ddl/database/'

需要HTTP / 1.1 401身份验证WWW-Authenticate:协商Set-Cookie:hadoop.auth =; 路径= /; HttpOnly缓存控制:必须重新验证,无缓存,无存储Content-Type:text / html; charset = ISO-8859-1 Content-Length:1321 Server:Jetty(7.6.0.v20230127)

HTTP / 1.1 200 OK WWW身份验证:协商YGY1cwVaADAgCAQ + iSTBHoAMCAReiQAQ + sf / nekePw09B / cboDrINa7qn + aENRuw2V + OW7Y7Rk9pOwGa8hrXC3afXKxap = sk-d = lea-s-c ==-Cookie: @ hadoop.company.com&T = Kerberos的&E = 15392343251&S = NWK / bFDbHQfsadfewe8PtjAsVHs =“; 路径= /; HttpOnly内容类型:application / json传输编码:分块服务器:Jetty(7.6.0.v20120127)

我意识到我对kerberos身份验证的基本理解存在差距,我正尝试着手速成课程,但是我真的只需要能够连接到此api。 任何帮助是极大的赞赏。

您需要提供HTTPSKerberosAuth实例而不是类本身,因此您的请求应为:

r = requests.get("https://apiServer.com", auth=HTTPSKerberosAuth())

请注意HTTPSKerberosAuth()的括号。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM