英文:
how to fix api request returns 426
问题
I have a problem that when I send a request using requests for my api, I receive a 426 response which means: "protocol Upgrade Required."
My code:
headers = {
'user-agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36'
}
req = requests.get(myApi, headers=headers, auth=user_name_password)
print(req.status_code)
the result:
426
When I try to put the API on the browser, I give the username and password and get the required result. So, I think that the API needs to be updated.
When I copy as curl, I take all of the headers and try to put them in my headers, but again, I have a 426 error.
英文:
I have a problem that when I send a request using requests for my api , I receive a 426 response which means: "protocol Upgrade Required"
My code:
headers= {
'user-agent ': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36'}
req = requests.get(myApi, headers=headers, auth=user_name_password)
print(req.status_code)
the result:
426
When I try to put the api on the browser , i give the username and password have a required result
So, I think that it is the api needs to be updated.
when I copy as curl , I take all of the header and try to put in my headers but again I have 426 error.
答案1
得分: 1
> 所以,我认为需要更新的是 API。
不,这不是426的意思,它是:
> 客户端错误响应代码表示服务器拒绝使用当前协议执行请求,但在客户端升级到不同协议后可能愿意执行请求。
所以 服务器 正在通知 客户端 需要升级,详细信息在 Upgrade
响应头中给出,要查看其值,请在代码的最后一行之后添加:
print(r.headers['Upgrade'])
英文:
> So, I think that it is the api needs to be updated.
No this is not what 426 means, it is
> client error response code indicates that the server refuses to perform the request using the current protocol but might be willing to do so after the client upgrades to a different protocol.
So server is informing that client needs upgrade, details are given in Upgrade
response header, to reveal its' value add
print(r.headers['Upgrade'])
after last line of your code
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论