繁体   English   中英

{“标题”:“不支持的媒体类型”,无论我尝试什么都会出错:I(

[英]{“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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM