【发布时间】:2019-11-12 14:06:30
【问题描述】:
我正在尝试使用 Python 的 API 请求。它类似于 /api/foo/bar/{name}
名称可能类似于“The/Avangers”。所以我的请求 uri 是 /api/foo/bar/The/Avangers。
我了解正斜杠会导致问题。我尝试使用“%2F”而不是“/”,但无济于事。
你知道如何解决这个问题吗?
我的代码:
import requests
x = "The/Avangers"
r = requests.get('myapp/api/sets{}'.format(x), headers=headers)
这是我收到的错误响应:
{
"http_response": {
"code": 404,
"message": "We could not find the resource you requested."
},
"code": 5,
"description": "",
"details": {},
"message": "HTTP method [GET] is not supported by the endpoint at the given
relative path (\/sets\/The\/Avangers)"
}
【问题讨论】:
-
欢迎来到 StackOverflow!你的问题有点令人困惑和误导——正斜杠当然不会引起问题。您能否将确切的输入发布到 requests.get,以及您收到的完整错误消息?
-
您好,谢谢。我正在分享我的请求样本。 import requests x = "The/Avangers" r = requests.get('myapp/api/sets{}'.format(x), headers=hdrs) 返回如下; {"http_response":{"code":404,"message":"我们找不到您请求的资源。"},"code":5,"description":"","details":{}," message":"给定相对路径 (\/sets\/The\/Avangers) 处的端点不支持 HTTP 方法 [GET]"}
-
@B.Karaduman 您需要将重要信息编辑到问题本身的正文中。评论可以随时消失。
标签: python api python-requests