简体   繁体   中英

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

Im working on pycharm flask and im trying to get similar news articles using: from googlesearch import search and I also called all the necessary libraries like:

pip install google
pip install googlesearch-python
pip install search_google

My code in app.py:

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

but I'm getting an error:

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

See stack trace below.

    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 -

429 Too Many Requests means that

The HTTP 429 Too Many Requests response status code indicates the user has sent too many requests in a given amount of time ("rate limiting").

A Retry-After header might be included to this response indicating how long to wait before making a new request.

You should limit number of queries in given amount time to avoid such situation.

i changed my IP address and it works now

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM