-
Notifications
You must be signed in to change notification settings - Fork 0
🔒 Add timeout to requests.get calls in SkillFetcher #2
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: main
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 | ||||
|---|---|---|---|---|---|---|
|
|
@@ -11,7 +11,7 @@ class SkillFetcher: | |||||
| def fetch_skill_from_github(self, author: str, name: str) -> str | None: | ||||||
| url = self.CLAW_HUB_RAW_GITHUB_URL.format(author=author, name=name) | ||||||
| try: | ||||||
| response = requests.get(url) | ||||||
| response = requests.get(url, timeout=10) | ||||||
| response.raise_for_status() # Raise an exception for HTTP errors | ||||||
| return response.text | ||||||
| except requests.exceptions.RequestException as e: | ||||||
|
|
@@ -22,7 +22,7 @@ def fetch_skill_from_clawhub_website(self, name: str) -> str | None: | |||||
| """Scrapes SKILL.md content from clawhub.ai.""" | ||||||
| url = self.CLAW_HUB_WEBSITE_URL.format(name=name) | ||||||
| try: | ||||||
| response = requests.get(url) | ||||||
| response = requests.get(url, timeout=10) | ||||||
|
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. |
||||||
| response.raise_for_status() | ||||||
| soup = BeautifulSoup(response.text, 'html.parser') | ||||||
|
|
||||||
|
|
@@ -46,7 +46,7 @@ def discover_author_via_github(self, name: str) -> str | None: | |||||
| url = self.GITHUB_SEARCH_API_URL.format(name=name) | ||||||
| headers = {"Accept": "application/vnd.github.v3+json"} | ||||||
| try: | ||||||
| response = requests.get(url, headers=headers) | ||||||
| response = requests.get(url, headers=headers, timeout=10) | ||||||
|
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. The GitHub Search API requires a
Suggested change
|
||||||
| response.raise_for_status() | ||||||
| data = response.json() | ||||||
| if data.get("total_count", 0) > 0: | ||||||
|
|
||||||
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.
Using a single value for
timeoutsets both the connection and read timeouts to that value. It is recommended to use a tuple (e.g.,(3.05, 10)) to specify separate timeouts. The connection timeout of3.05is slightly larger than a multiple of 3 (the default TCP retransmission window), which is a common best practice. Also, consider defining this timeout as a class-level constant to avoid repeating the magic number10across multiple methods.