使用Python requests_kerberos的API连接

问题描述 投票:0回答:1

这是我第一次尝试使用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':'必须重新验证,没有缓存,没有商店','内容类型':'text / html; charset = ISO-8859-1','WWW-Authenticate':'Negotiate'}

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:Negotiate Set-Cookie:hadoop.auth =;路径= /; HttpOnly Cache-Control:必须重新验证,无缓存,无存储内容类型:text / html; charset = ISO-8859-1内容长度:1321服务器:Jetty(7.6.0.v20230127)

HTTP / 1.1 200 OK WWW-Authenticate:协商YGY1cwVaADAgCAQ + iSTBHoAMCAReiQAQ + sf / nekePw09B / cboDrINa7qn + aENRuw2V + OW7Y7Rk9pOwGa8hrXC3rXKxCk = Set-Cookie:hadoop.auth =“u = svc-qa-dsafqa-dev&p = svc-fd-itdflea-dev @ hadoop.company.com&T = Kerberos的&E = 15392343251&S = NWK / bFDbHQfsadfewe8PtjAsVHs =“;路径= /; HttpOnly Content-Type:application / json Transfer-Encoding:chunked Server:Jetty(7.6.0.v20120127)

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

python api hadoop hive kerberos
1个回答
0
投票

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

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

请注意HTTPSKerberosAuth()中的括号。

© www.soinside.com 2019 - 2024. All rights reserved.