简体   繁体   English

使用Python request_kerberos的API连接

[英]API Connection using Python requests_kerberos

This is my first experience trying to connect to an API through python (from windows) using Kerberos authentication. 这是我第一次尝试使用Kerberos身份验证通过python(从Windows)连接到API的经验。 I have been working on it for a few days and my progress has stalled. 我已经为此工作了几天,但进度一直停滞不前。 Here are just a few of the references I have been using: 以下是我一直在使用的一些参考资料:

This is the best tutorial I have found, but it appears to be using a deprecated module rather than the requests_kerberos: http://python-notes.curiousefficiency.org/en/latest/python_kerberos.html 这是我找到的最好的教程,但似乎使用的是不推荐使用的模块,而不是requests_kerberos: http : //python-notes.curiousefficiency.org/en/latest/python_kerberos.html

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

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

Here is what I have tried so far(I will be masking sensitive information): 到目前为止,这是我尝试过的操作(我将屏蔽敏感信息):

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

Here is some output: 这是一些输出:

r.status_code

401 401

r.headers

{'Content-Length': '1321', 'Set-Cookie': 'hadoop.auth=; {'Content-Length':'1321','Set-Cookie':'hadoop.auth =; Path=/; 路径= /; HttpOnly', 'Server': 'Jetty(7.6.0.v20120127)', 'Cache-Control': 'must-revalidate,no-cache,no-store', 'Content-Type': 'text/html;charset=ISO-8859-1', 'WWW-Authenticate': 'Negotiate'} 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>

Does any of this output at least indicate that the server is getting my request? 此输出是否至少表明服务器正在接收我的请求?

If I connect to the API from our linux environment using curl it works just fine and I receive the expected output: 如果我使用curl从我们的Linux环境连接到API,它就可以正常工作,并且我会收到预期的输出:

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

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

HTTP/1.1 200 OK WWW-Authenticate: Negotiate 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="; 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 =“; Path=/; 路径= /; HttpOnly Content-Type: application/json Transfer-Encoding: chunked Server: Jetty(7.6.0.v20120127) HttpOnly内容类型:application / json传输编码:分块服务器:Jetty(7.6.0.v20120127)

I realize that there is a gap in my fundamental understanding of kerberos authentication and I'm trying to bring to do a crash course, but I really just need to be able to connect to this api. 我意识到我对kerberos身份验证的基本理解存在差距,我正尝试着手速成课程,但是我真的只需要能够连接到此api。 Any help is greatly appreciated. 任何帮助是极大的赞赏。

You need to provide an instance of HTTPSKerberosAuth rather than the class itself, so your request should be: 您需要提供HTTPSKerberosAuth实例而不是类本身,因此您的请求应为:

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

Note the parentheses in HTTPSKerberosAuth() . 请注意HTTPSKerberosAuth()的括号。

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

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