内部服务器错误,在Python 3.7中传递API端点URL中的参数时发生。

huangapple go评论71阅读模式
英文:

Internal server error while passing parameters in API endpoint URL in Python 3.7

问题

以下是翻译后的代码部分:

我想执行一个GET操作到一个API端点以下是基本URL

url = "https://abcd.eu/v{version}/lists/{list-id}/terms/{term-id}/preferred-name"
headers = {'Accept': 'application/json'}

params = {'version': '1', 'list-id': '102', 'term-id': '103'}

r = requests.get(url, auth=('ghfgdhg', 'hgdfhghd'), params=params)
print(r.text)

如果需要进一步的帮助,请随时提出。

英文:

I would like to perform a GET operation to an API endpoint. Following is the base URL.

#GET /v{version}/lists/{list-id}/terms/{term-id}/preferred-name

url = "https://abcd.eu/v{version}/lists/{list-id}/terms/{term-id}/preferred-name"
headers = {'Accept': 'application/json'}

params = {'version': '1', 'list-id': '102', 'term-id': '103'}

r = requests.get(url, auth=('ghfgdhg', 'hgdfhghd'), params = params)
print(r.text)

However, I am getting an internal server error. Any help is highly appreciated.

答案1

得分: 1

内部服务器错误通常意味着服务器无法处理您提供的内容。

我建议首先尝试在Postman(或任何其他REST客户端)上运行API,看看是否能正常工作。

如果一切正常,我会尝试构建URL(而不使用参数),像这样:

version, list_id, term_id = '1', '102', '103'

url = f"https://abcd.eu/v{version}/lists/{list_id}/terms/{term_id}/preferred-name"
headers = {'Accept': 'application/json'}

r = requests.get(url, auth=('ghfgdhg', 'hgdfhghd'), headers=headers)

如果您需要进一步的帮助,请告诉我。

英文:

Internal server error usually means the server could not process what you have given it

I recommend trying the API running with postman first (or any other rest client) to try if it functions

If everything works I would try to construct the url (and not use params) like this:

version, list_id, term_id = '1', '102', '103'

url = f"https://abcd.eu/v{version}/lists/{list_id}/terms/{term_id}/preferred-name"
headers = {'Accept': 'application/json'}

r = requests.get(url, auth=('ghfgdhg', 'hgdfhghd'), headers=headers)

huangapple
  • 本文由 发表于 2023年2月27日 04:58:18
  • 转载请务必保留本文链接:https://go.coder-hub.com/75574972.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定