简体   繁体   中英

Why does requests.post raise 404 Not found code?

does anyone have any idea, why the output of this script, where i use requests.post to login is code 404, Not found, and the same script, where I use only requests.get has code 200 OK? What should I change?

import requests
URL = 'https://www.stratfor.com/login'
session = requests.Session()
page = session.post(URL)
print(page.status_code, page.reason)

Thank you.

it seem to be worked with get request and should returned 405 but it depends on the server

One good way to note the right page to log in is to log the network calls.

After looking at the calls, a request is sent to

URL = https://www.stratfor.com/api/v3/user/login

The API endpoint actually expects a payload like this:

payload = {username: "YOU_USER", password: "YOUR_PASS"}

Try something like this:

r = requests.post(URL,json=payload)

You might need to pass more headers, which you can poke the network call log for. Although, it seems like that user and password are passed as raw strings here? If so, that's definitely not safe.

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