【问题标题】:How to solve 405 error with Python requests?如何使用 Python 请求解决 405 错误?
【发布时间】:2021-06-05 12:06:09
【问题描述】:

我正在尝试使用 requests 库通过 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}')

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

我在代码中做错了什么?

【问题讨论】:

标签: python python-3.x python-requests http-status-code-405


【解决方案1】:

这是already answeredServer Fault@Samit

405 状态码响应意味着您尝试的 HTTP 方法不是 允许。比如说,如果服务器上不允许 PUT 请求,它将 拒绝客户端的PUT 请求,响应码为405 Method not allowed

因此,在您的情况下,POST 方法可能不允许在哪个 您正在发送请求,而请求只是拒绝您 通过发送405 错误响应来提出任何POST 请求。

【讨论】:

  • 我认为也可能是因为请求无效,不仅仅是服务器端不允许。
猜你喜欢
  • 2021-03-11
  • 2014-11-23
  • 2021-02-03
  • 2014-04-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-04-24
  • 2021-08-07
相关资源
最近更新 更多