簡體   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