requests.exceptions.HTTPError:429 客户端错误:对 url 的请求过多

时间:2021-02-25 14:16:53

标签: python python-requests

我正在研究 pycharm 烧瓶,我正在尝试使用以下方法获取类似的新闻文章:from googlesearch import search 我还调用了所有必要的库,例如:

pip install google
pip install googlesearch-python
pip install search_google

我在 app.py 中的代码:

    news_title = article.title  # title of the article given by the user 
    similar = search(news_title, num_results=5)

但我收到一个错误:

requests.exceptions.HTTPError: 429 Client Error: Too Many Requests for url:

请参阅下面的堆栈跟踪。

    Traceback (most recent call last):
      File "C:\Users\user\PycharmProjects\flaskProject\venv\lib\site-packages\flask\app.py", line 2447, in wsgi_app
        response = self.full_dispatch_request()
      File "C:\Users\user\PycharmProjects\flaskProject\venv\lib\site-packages\flask\app.py", line 1952, in full_dispatch_request
        rv = self.handle_user_exception(e)
      File "C:\Users\user\PycharmProjects\flaskProject\venv\lib\site-packages\flask\app.py", line 1821, in handle_user_exception
        reraise(exc_type, exc_value, tb)
      File "C:\Users\user\PycharmProjects\flaskProject\venv\lib\site-packages\flask\_compat.py", line 39, in reraise
        raise value
      File "C:\Users\user\PycharmProjects\flaskProject\venv\lib\site-packages\flask\app.py", line 1950, in full_dispatch_request
        rv = self.dispatch_request()
      File "C:\Users\user\PycharmProjects\flaskProject\venv\lib\site-packages\flask\app.py", line 1936, in dispatch_request
        return self.view_functions[rule.endpoint](**req.view_args)
      File "C:\Users\user\PycharmProjects\flaskProject\app.py", line 31, in send
        similar = search(news_title, num_results=5)
      File "C:\Users\user\PycharmProjects\flaskProject\venv\lib\site-packages\googlesearch\__init__.py", line 29, in search
        html = fetch_results(term, num_results, lang)
      File "C:\Users\user\PycharmProjects\flaskProject\venv\lib\site-packages\googlesearch\__init__.py", line 16, in fetch_results
        response.raise_for_status()
      File "C:\Users\user\PycharmProjects\flaskProject\venv\lib\site-packages\requests\models.py", line 941, in raise_for_status
        raise HTTPError(http_error_msg, response=self)
    requests.exceptions.HTTPError: 429 Client Error: Too Many Requests for url: https://www.google.com/sorry/index?continue=https://www.google.com/search%3Fq%3DFebruary%2B22,%2B2021%2BMerrick%2BGarland%2Bconfirmation%2Bhearing%26num%3D6%26hl%3Den&hl=en&q=EgTVr76lGLDW3oEGIhkA8aeDS8JiejR13ZuPCAsRa9kS_PJw4vRYMgFy ```


    127.0.0.1 - - [25/Feb/2021 15:50:40] "POST /send HTTP/1.1" 500 -

2 个答案:

答案 0 :(得分:1)

429 Too Many Requests 表示

<块引用>

HTTP 429 Too Many Requests 响应状态代码指示用户 在给定的时间内发送了太多请求(“rate 限制”)。

此响应中可能包含 Retry-After 标头,指示如何 在发出新请求之前等待很长时间。

您应该限制给定时间内的查询次数,以避免出现这种情况。

答案 1 :(得分:0)

我更改了我的 IP 地址,现在可以使用了