簡體   English   中英

錯誤:Python 中的 url 超出了最大重試次數

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM