Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setting Timeout on Instantiation for GoogleSearch #40

Open
zach-two opened this issue Mar 17, 2023 · 3 comments
Open

Setting Timeout on Instantiation for GoogleSearch #40

zach-two opened this issue Mar 17, 2023 · 3 comments
Labels
enhancement New feature or request

Comments

@zach-two
Copy link

zach-two commented Mar 17, 2023

Currently it is not possible to set a timeout threshold on Instantiation of a GoogleSearch client and instead it defaults to a hard-coded value of 60,000.

@aliayar aliayar added the enhancement New feature or request label Mar 20, 2023
@ilyazub
Copy link
Contributor

ilyazub commented Mar 22, 2023

It's possible to tweak the timeout by using the SerpApiClient. Example project in web-IDE.

params = {
    "engine": "google_maps",
    "q": q,
    "type": "search",
    "ll": "@40.7455096,-74.0083012,14z",
    "api_key": os.getenv("SERPAPI_KEY"),
}

# Timeout is set to 1 ms to illustrate that it works.
# In a real project, some searches can take up to 450 seconds on the SerpApi side:
# Reason: parameters complexity and other factors on target websites' side.
# Example: SerpApiClient(params, timeout=90)
search = SerpApiClient(params, timeout=1)

Outputs:

requests.exceptions.ReadTimeout: HTTPSConnectionPool(host='serpapi.com', port=443): Read timed out. (read timeout=1)

@zach-two, what do you think about the proposed solution?

@zach-two
Copy link
Author

Can you please clarify if the timeout units are seconds or milliseconds?
Since in the underlying implementation the timeout is passed to the get method of requests and the docs mention it is in seconds.

@ilyazub
Copy link
Contributor

ilyazub commented Mar 24, 2023

It's in seconds, according to requests source code and urllib code documentation. (I've updated the code sample above to reflect that timeout is in seconds.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants