尝试从API检索数据时出现“ URL超过最大重试次数:”错误

时间:2019-03-11 01:47:50

标签: python json api request

我正在尝试访问API。我之前访问过它非常好,没有错误,并且当我尝试访问一个API时,要遍历多个页面,这似乎给了我“超出url的最大重试次数”错误。我已经进行了研究,并尝试通过添加try除个案以外的方法来解决此问题,但随后陷入无限循环。

请记住,在我的IDE中进行测试时,此代码可以很好地工作,但是在运行.py文件或.exe文件时,它会出错。在他们这方面可能是一个问题吗?我注释掉了我所有的新更改,并返回到以前可以使用的旧代码,但是现在它也给了我这个错误。即使尝试通过删除循环来仅检索一个数据,仍然会给我错误。

此帖子与其他帖子不同,因为显示的错误是SSLError,而不是大多数其他帖子一样的ConnectionError。

顺便说一句,默认情况下,类型1 = 1v1,区域=全部。

def ranked_info():
type1, region1 = get_rank_info()
tv5.delete(*tv5.get_children())
for page in range(1, 3):
    url = "https://api.brawlhalla.com/rankings/"
    url2 = type1 + "/"
    url3 = region1 + "/"
    page_num = str(page)
    url4 = "?api_key=KEY"
    final = url + url2 + url3 + page_num + url4
    json_data_rank = requests.get(final).json()
    for x in range(0, 50):
        if type1 == "1v1":
            try:
                name = json_data_rank[x]["name"]
            except KeyError:
                name = "Error"
            best_legend = str(json_data_rank[x]["best_legend"])
            best_legend_games = str(json_data_rank[x]["best_legend_games"])
            best_legend_wins = str(json_data_rank[x]["best_legend_wins"])
            best_legend_winloss = best_legend_wins +"-"+ str(int(best_legend_games)-int(best_legend_wins))
        else:
            try:
                teamname = json_data_rank[x]["teamname"]
            except KeyError:
                teamname = "Error"
        rank = json_data_rank[x]["rank"]
        rating = str(json_data_rank[x]["rating"])
        tier = json_data_rank[x]["tier"]
        games = str(json_data_rank[x]["games"])
        wins = str(json_data_rank[x]["wins"])
        winloss = wins +"-"+ str(int(games)-int(wins))
        region = json_data_rank[x]["region"]
        peak_rating = str(json_data_rank[x]["peak_rating"])
        if type1 == "1v1":
            tv5.insert('', 'end', text=rank, values=(region, name, tier, winloss, rating, peak_rating, best_legend, best_legend_winloss))
        else:
            tv5.insert('', 'end', text=rank, values=(region, teamname, tier, winloss, rating, peak_rating, "N/A", "N/A"))



Traceback (most recent call last):
  File "C:\Users\Samuel\Anaconda3\lib\tkinter\__init__.py", line 1705, in __call__
    return self.func(*args)
  File "C:\Users\Samuel\Documents\BrawlApp\BrawlStats.py", line 29, in getText
    json_data = user_name("")
  File "C:\Users\Samuel\Documents\BrawlApp\BrawlStats.py", line 71, in user_name
    json_data = requests.get(final_url_user).json()
  File "C:\Users\Samuel\Anaconda3\lib\site-packages\requests\api.py", line 75, in get
    return request('get', url, params=params, **kwargs)
  File "C:\Users\Samuel\Anaconda3\lib\site-packages\requests\api.py", line 60, in request
    return session.request(method=method, url=url, **kwargs)
  File "C:\Users\Samuel\Anaconda3\lib\site-packages\requests\sessions.py", line 533, in request
    resp = self.send(prep, **send_kwargs)
  File "C:\Users\Samuel\Anaconda3\lib\site-packages\requests\sessions.py", line 646, in send
    r = adapter.send(request, **kwargs)
  File "C:\Users\Samuel\Anaconda3\lib\site-packages\requests\adapters.py", line 514, in send
    raise SSLError(e, request=request)
requests.exceptions.SSLError: HTTPSConnectionPool(host='api.brawlhalla.com', port=443): Max retries exceeded with url: /rankings/1v1/all/1?name=&api_key=KEY (Caused by SSLError("Can't connect to HTTPS URL because the SSL module is not available."))

0 个答案:

没有答案