[英]Error: Max retries exceeded with url in Python
我正在嘗試從 API 中獲取一些數據。但是,我遇到了以下錯誤。
Max retries exceeded with url: /api/search?accept=application%2Fjson&Authorization=Bearer......
我正在嘗試遵循 python 中的代碼行。
token = 'aagagagagagagagaggagagag'
def get_val (ont, term):
#set the url
url = 'https://host:port/api/search'
#set the header
Authorization = 'Bearer ' + token
header = {
'accept': */*,
'Authorization': Authorization,
}
#set the parameters
params = {'ontology': ont, 'q': term, 'header':header}
#send request
response = requests.get(url, header)
get_val('mesh', 'ibu')
以下是 curl 命令(通過包裝器):
curl -X 'GET' \
'https://host:port/api/search?from=0&ontology=mesh&q=ibu&size=10' \
-H 'accept: */*' \
-H 'Authorization: Bearer ''
非常感謝任何幫助。
您沒有將params
傳遞給requests.get()
因此 API 可能在返回正確數據時出現問題,您的請求失敗了。
嘗試使用:
requests.get(url, params=params, headers=header)
在 get function 中添加“verify=False”可以提供 API 響應。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.