Python GoogleSearch module error : "TypeError: search() got an unexpected keyword argument 'tld' "


Here is my code, it was working properly before I was not getting an error while using it. I don’t understand how it happened even though I didn’t change with it. :

    results = []
for query in my_list:
    results.append(search(query, tld="com", num=1, stop=1, pause=2))


results.append(search(query, tld="com", num=1, stop=1, pause=2))
TypeError: search() got an unexpected keyword argument 'tld'
Asked By: E.MRZ



It is from the google python package. it is still working of all the versions.

version parameters :

  • query : query string that we want to search for.
  • tld : tld stands for top level domain which means we want to search our result on or or some other domain.
  • lang : lang stands for language.
  • num : Number of results we want.
  • start : First result to retrieve.
  • stop : Last result to retrieve. Use None to keep searching forever.
  • pause: Lapse to wait between HTTP requests. Lapse too short may cause Google to block your IP. Keeping significant lapse will make your program slow but its safe and better option.
  • Return : Generator (iterator) that yields found URLs. If the stop parameter is None the iterator will loop forever.

Here is your real problem:

There is one more python package with the module name as googlesearch

Link here

Since it might be installed on your environment, this might be calling this module which does not have these parameters included.

The BlockBuster Solution is: (tested these both packages on local)

  • Delete your Python Environment
  • Create a new one
  • install pip install beautifulsoup4 and pip install google
  • Now use your code which will work like charm.
  • Never install the pip install googlesearch-python python package
Answered By: Tamil Selvan

It is necessary to install the google library, installing this library stopped producing the error:

pip install google

After you do everything they suggested, don’t forget to restart your kernel. took me like 10 min to realize why it still wasn’t working for me, then I was like ‘DUH!’ and it works now.

Answered By: Jon R Bush
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.