如何解决Python请求的405错误?

2024-04-27 21:12:22 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图使用请求库使用Python脚本登录到一个网站,但我一直收到一个405错误,我不明白为什么会收到它

import requests

payload = {
'guid': 'xxxxx',
'password': "xxxx"
}

head = {'Host': 'www.blockchain.com',
'Connection': 'keep-alive',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.94 Safari/537.36',
'Upgrade-Insecure-Requests': '1',
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8',
'Accept-Encoding': 'gzip, deflate, br',
'Accept-Language': 'en-US,en;q=0.9'
    }

#This URL will be the URL that your login form points to with the "action" tag.
url_address = 'https://login.blockchain.com/#/login'

with requests.Session() as session:
    post = session.post(url_address, data=payload, headers = head, allow_redirects=True)

print(f'{post}')

我检查了表单,输入字段的名称似乎也正确

我在代码中做错了什么

passname hereloginname here


Tags: theimagecomurlapplicationwithloginxml
1条回答
网友
1楼 · 发布于 2024-04-27 21:12:22

这是{a3}在{a2}上的{a1}:

405 status code response means the HTTP method you are trying is not allowed. Say, if a PUT request is not allowed on a server, it will reject the client's PUT request with an response code 405 Method not allowed.

So, in your case also, the POST method might not be allowed on which you are sending the request and the request is simply denying you to make any POST request by sending 405 error response.

相关问题 更多 >