简体   繁体   中英

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. 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.

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. Is this the right way to be doing a auth request using a POST method?

Here is the page describing how the auth API works: 在此处输入图片说明

It just wants you to make a normal POST with username and password .

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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