error while catching pytrends.exceptions.ResponseError in python

Viewed 1031

I am trying to catch an exception that is thrown by google when they lock you out of their servers in pytrends.

Here is the exact error message I get:

  File "/usr/local/lib/python3.7/site-packages/pytrends/request.py",     line 101, in _get_data
'response with code {0}.'.format(response.status_code), response=response)
pytrends.exceptions.ResponseError: The request failed: Google returned a response with code 429.

I tried running except pytrends.exceptions.ResponseError: but when I do that I get an attribute error AttributeError: 'TrendReq' object has no attribute 'exceptions'

If anyone knows the way to catch this it would be great to know, thanks!

1 Answers

To import the error :

from pytrends.exceptions import ResponseError

Then you can catch it :

try:
    pass  # normal behaviour
except ResponseError:
    pass  # treat your error
Related