英文:
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)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论