简体   繁体   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 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

Please try to do this.请尝试这样做。

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.

相关问题 接收错误415:使用REST API发送GET请求时,媒体类型不受支持 - Receiving Error 415 : Unsupported media type when sending GET request with a REST API 如何使用请求修复Python中的&#39;415 Unsupported Media Type&#39;错误 - How to fix '415 Unsupported Media Type' error in Python using requests requests.exceptions.HTTPError: 415 Client Error Unsupported Media Type when using python zeep - requests.exceptions.HTTPError: 415 Client Error Unsupported Media Type when using python zeep Python GET 请求 - 415 不支持的媒体类型 - Python GET requests - 415 unsupported media type Watson Discovery Service create_collection()api调用返回错误415:不支持的媒体类型 - Watson Discovery service create_collection() api call returns Error 415: Unsupported Media Type urllib2:HTTP错误415:不支持的媒体类型:Google App Engine Python,XML - urllib2: HTTP Error 415: Unsupported Media Type: Google App Engine Python, XML 为什么我会不断收到415 WatsonException:错误:Python中不支持的媒体类型? - Why do I keep getting 415 WatsonException: Error: unsupported media type in Python? 向服务器发送数据时 HTTP 415 不支持的媒体类型客户端 - HTTP 415 Unsupported Media Type client when sending data to server 如何修复 python 对 Twilio 的 POST 请求上的“不支持的媒体类型”错误 - How to fix 'Unsupported media type" error on python POST request to Twilio BlueJeans ApiException:415“不支持的媒体类型” - BlueJeans ApiException: 415 “Unsupported Media Type”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM