2
votes

After few tries ... getting following response for google search query as given below. Anybody had solution to this please help?

search(query=self.name,tld='com',lang='en',num=100,stop=100,pause=5):

File "C:\Users\img_cart_project\venv\lib\site-packages\googlesearch_init_.py", line 305, in search html = get_page(url, user_agent, verify_ssl) File "C:\Users\img_cart_project\venv\lib\site-packages\googlesearch_init_.py", line 174, in get_page response = urlopen(request) File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.1776.0_x64__qbz5n2kfra8p0\lib\urllib\request.py", line 222, in urlopen return opener.open(url, data, timeout) File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.1776.0_x64__qbz5n2kfra8p0\lib\urllib\request.py", line 531, in open response = meth(req, response) File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.1776.0_x64__qbz5n2kfra8p0\lib\urllib\request.py", line 640, in http_response response = self.parent.error( File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.1776.0_x64__qbz5n2kfra8p0\lib\urllib\request.py", line 563, in error result = self._call_chain(*args) File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.1776.0_x64__qbz5n2kfra8p0\lib\urllib\request.py", line 502, in _call_chain result = func(*args) File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.1776.0_x64__qbz5n2kfra8p0\lib\urllib\request.py", line 755, in http_error_302 return self.parent.open(new, timeout=req.timeout) File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.1776.0_x64__qbz5n2kfra8p0\lib\urllib\request.py", line 531, in open response = meth(req, response) File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.1776.0_x64__qbz5n2kfra8p0\lib\urllib\request.py", line 640, in http_response response = self.parent.error( File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.1776.0_x64__qbz5n2kfra8p0\lib\urllib\request.py", line 569, in error return self._call_chain(*args) File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.1776.0_x64__qbz5n2kfra8p0\lib\urllib\request.py", line 502, in _call_chain result = func(*args) File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.1776.0_x64__qbz5n2kfra8p0\lib\urllib\request.py", line 649, in http_error_default raise HTTPError(req.full_url, code, msg, hdrs, fp) urllib.error.HTTPError: HTTP Error 429: Too Many Requests

1
Please edit your post to make it more understandable.tibetiroka

1 Answers

0
votes

Possible duplicate.

Handle the Error in your code

Assuming that you are using the google python package and not the google-api-python-client the line you provided works fine for me.

Steps followed

  1. Create a clean python environment (using virtualenv in my case, install with pip): virtualenv google_search_env
  2. Activate the environment: source google_search_env/bin/activate for linux or source google_search_env/scripts/activate for windows.
  3. Install dependencies: pip install beautifulsoup4 google
  4. Run you python script: python search_client.py
# search_client.py

from googlesearch import search 

try:
    searche_results = search(query="test search", tld='com',lang='en',num=5,stop=10,pause=1)
    [print("result: "+searche_result) for searche_result in searche_results]
except HTTPError:
    print("429 HTTP Error.")
    # more code...
except:
    print("There was an issue while fetching results.")

This should print search results for test search term or the custom exception.