簡體   English   中英

“標題”:“不支持的媒體類型”,“狀態”:從 python 請求 API 時出現 415 錯誤

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

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