[英]I'm getting an error when I try to run this code - unsupported operand type(s) for /: 'str' and 'int'
[英]{“title”:“Unsupported Media Type”,Error for no matter what i try :I(
下面是我的代碼,無論我嘗試什么,我總是得到 415。有人可以看看,讓我知道我錯過了什么。
返回響應:
{"title":"Unsupported Media Type","status":415,"detail":"This resource supports only application/json,application/octet-stream,application/xml,application/*+json,text/plain,text/xml,application/x-www-form-urlencoded,application/*+xml,multipart/form-data,*/*, but you've sent request with Content-Type application/octet-stream
代碼:
import requests,json
url= "https://x.y.x.z"
headers= {'Accept': 'application/json', 'X-AUTH-TOKEN': 't0K3N'}
payload= {'isDeleted': 'false',*emphasized text*}
response = requests.request("POST", url, headers=headers, data=json.dumps(payload,ensure_ascii=True),verify= False)
print(response.text)
錯誤讀取
此資源僅支持 application/json [... 和一堆其他類型]
向接收服務器宣布媒體類型的方法是設置Content-Type
header。
headers= {
'Accept': 'application/json', # this is the data type you expect for a response
'X-AUTH-TOKEN': 't0K3N',
'Content-Type': 'application/json; charset=utf-8', # this is the data type you send
}
payload = {'isDeleted': 'false', 'and': 'some more data'}
data = json.dumps(payload, ensure_ascii=True)
response = requests.request("POST", url, headers=headers, data=data,verify= False)
# response will be JSON-encoded if the server is well-behaved
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.