![](/img/trans.png)
[英]Receiving Error 415 : Unsupported media type when sending GET request with a REST API
[英]“title”:“Unsupported Media Type”,“status”:415 error when request API from python
Why is the same restful api API when I use it with react and java android I don't get error 415 but when I use python requests I get an error: "title":"Unsupported Media Type","status":415
URL = "http://localhost:44327/api/UserOfficial/UserOfficialAuthenticate"
def Login():
data = {
'username': 'hienkieu',
'password': '197353995'
}
length = len(json.dumps(data))
hearder = {
'accept': 'application/json',
'content-Type' : 'application/json',
'content-Length': length
}
r = requests.post(URL, data, hearder)
return r.text
請嘗試這樣做。
URL = "http://localhost:44327/api/UserOfficial/UserOfficialAuthenticate"
def Login():
data = {
'sername': 'hienkieu',
'password': '197353995'
}
data = json.dumps(data) # <<<<<<<<<////////////// Edit is here
length = len(json.dumps(data))
hearder = {
'accept': 'application/json',
'content-Type' : 'application/json',
'host': '104.154.118.39',
'content-Length': length
}
r = requests.post(URL, data, hearder)
return r.text
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.