简体   繁体   English

如何通过POST请求使用Python请求正确进行身份验证

[英]How to properly authenticate using Python requests via a POST request

I am using the REST API for iObeya, I wish to use Python Requests but currently I cannot authenticate with the server. 我正在为iObeya使用REST API,我希望使用Python请求,但目前无法通过服务器进行身份验证。 The documentation states that you can authenticate using a POST request and upon return, you should get a cookie called 'JSESSIONID' when the auth is correct. 该文档指出,您可以使用POST请求进行身份验证,并且在返回时,如果身份验证正确,则应该获得一个名为“ JSESSIONID”的cookie。

So far I have this: 到目前为止,我有这个:

url = 'https://link-to.com/iobeya/'
auth_url = 'https://link-to.com/iobeya/j_spring_security_check'
headers = {"content-type": "application/x-www-form-urlencoded; charset=utf-8"}

session = requests.Session()
session.auth = ("username", "password")

auth = session.post(url, verify=False)

r = session.get(url, verify=False, headers=headers)

print(r.status_code)

print(r.headers)

print(r.cookies)

The return of cookies is null. Cookie的返回为null。 Is this the right way to be doing a auth request using a POST method? 这是使用POST方法执行身份验证请求的正确方法吗?

Here is the page describing how the auth API works: 这是描述auth API如何工作的页面: 在此处输入图片说明

It just wants you to make a normal POST with username and password . 它只希望您使用usernamepassword进行常规POST。

auth_url = 'https://link-to.com/iobeya/j_spring_security_check'

session = requests.Session()
auth = session.post(auth_url, data={'username': username, 'password': password})

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

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