Skip to content
This repository was archived by the owner on Jun 25, 2024. It is now read-only.

Add timeout to requests calls #17

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

pixeebot[bot]
Copy link

@pixeebot pixeebot bot commented Apr 18, 2024

Many developers will be surprised to learn that requests library calls do not include timeouts by default. This means that an attempted request could hang indefinitely if no connection is established or if no data is received from the server.

The requests documentation suggests that most calls should explicitly include a timeout parameter. This codemod adds a default timeout value in order to set an upper bound on connection times and ensure that requests connect or fail in a timely manner. This value also ensures the connection will timeout if the server does not respond with data within a reasonable amount of time.

While timeout values will be application dependent, we believe that this codemod adds a reasonable default that serves as an appropriate ceiling for most situations.

Our changes look like the following:

 import requests
 
- requests.get("http://example.com")
+ requests.get("http://example.com", timeout=60)
More reading

I have additional improvements ready for this repo! If you want to see them, leave the comment:

@pixeebot next

... and I will open a new PR right away!

Powered by: pixeebot (codemod ID: pixee:python/add-requests-timeouts)

Copy link
Author

pixeebot bot commented Apr 26, 2024

I'm confident in this change, and the CI checks pass, too!

If you see any reason not to merge this, or you have suggestions for improvements, please let me know!

Copy link
Author

pixeebot bot commented Apr 27, 2024

Just a friendly ping to remind you about this change. If there are concerns about it, we'd love to hear about them!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

0 participants