如何解决“标题”:“不支持的媒体类型”,“状态”:从 python 请求 API 时出现 415 错误
为什么我在 react 和 java android 中使用相同的 restful api API 我没有收到错误 415 但是当我使用 python 请求时我收到一个错误:"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
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。