-
Notifications
You must be signed in to change notification settings - Fork 404
Add timeout to contributor avatar fetch #1057
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -7,6 +7,8 @@ | |||||||||||||||
| import requests | ||||||||||||||||
| from PIL import Image | ||||||||||||||||
|
|
||||||||||||||||
| REQUEST_TIMEOUT_SECONDS = 10 | ||||||||||||||||
|
|
||||||||||||||||
|
|
||||||||||||||||
| def main(directory): | ||||||||||||||||
| contributors = [] | ||||||||||||||||
|
|
@@ -38,7 +40,10 @@ def main(directory): | |||||||||||||||
|
|
||||||||||||||||
| for index, contributor in enumerate(contributors): | ||||||||||||||||
| file_name = os.path.join(directory, str(index) + ".jpeg") | ||||||||||||||||
| response = requests.get(contributor["avatar_url"]) | ||||||||||||||||
| response = requests.get( | ||||||||||||||||
| contributor["avatar_url"], timeout=REQUEST_TIMEOUT_SECONDS | ||||||||||||||||
| ) | ||||||||||||||||
|
Comment on lines
+43
to
+45
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. While adding a timeout is a good practice to prevent the script from hanging, it's also important to ensure the request was successful before processing the response. Adding
Suggested change
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks, accepted in 1e1baef by adding response.raise_for_status() after the avatar request. |
||||||||||||||||
| response.raise_for_status() | ||||||||||||||||
| file = open(file_name, "wb") | ||||||||||||||||
| file.write(response.content) | ||||||||||||||||
| file.close() | ||||||||||||||||
|
|
||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Self-review: Keeping the timeout as a named constant makes it easy to tune later and avoids leaving a maintenance script blocked indefinitely on one slow avatar response.