我想在 post 請求中將用戶輸入(用戶名和密碼)發送到 Header。到目前為止我有這個-
import requests
import urllib3
import json
import getpass
urllib3.disable_warnings()
url = "https://127.0.0.1"
username = raw_input("Enter the username: ")
password = getpass.getpass()
payload = "relevance=(members of computer group whose (name = \"ABC\") of computers)"
headers = {
'username': username,
'password': password,
'Content-Type': 'application/xml',
}
response = requests.post(url, verify=False, headers=headers, payload=payload)
print(response)
我收到 401 錯誤。但是當我使用基本身份驗證時,它可以作業-
headers = {
'Authorization': 'Basic akjrgbierhgiehg',
'Content-Type': 'application/xml',
}
請指教。
uj5u.com熱心網友回復:
用戶名和密碼在auth請求的關鍵字中。從標題中洗掉它們但將它們傳入requests.post
headers = {
'Content-Type': 'application/xml',
}
response = requests.post(url, verify=False, headers=headers, payload=payload, auth=(username, password))
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/523060.html
標籤:Pythonxml邮政
上一篇:如何使用jsonobject主體為POST方法呼叫JsonArrayRequest(回應是一個物件陣列)
下一篇:將受密碼保護的檔案上傳到服務器
