簡體   English   中英

如何解決 Python 請求的 405 錯誤?

[英]How to solve 405 error with Python requests?

我正在嘗試使用 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}')

我檢查了表格,輸入字段的名稱似乎也正確。

我在我的代碼中做錯了什么?

密碼在這里 登錄名在這里

@SamitServer Fault已經回答了這個問題:

405 狀態碼響應意味着您正在嘗試的 HTTP 方法是不允許的。 比如說,如果服務器上不允許PUT請求,它將拒絕客戶端的PUT請求,並返回響應代碼405 Method not allowed

因此,在您的情況下,也可能不允許您發送請求的POST方法,並且該請求只是通過發送405錯誤響應來拒絕您發出任何POST請求。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM