Title: On a multi-thread context, the use of this method could lead to "HTTPSConnectionPool ... Max retries exceeded with url..." · Issue #35 · clearbit/clearbit-python · GitHub
Open Graph Title: On a multi-thread context, the use of this method could lead to "HTTPSConnectionPool ... Max retries exceeded with url..." · Issue #35 · clearbit/clearbit-python
X Title: On a multi-thread context, the use of this method could lead to "HTTPSConnectionPool ... Max retries exceeded with url..." · Issue #35 · clearbit/clearbit-python
Description: clearbit-python/clearbit/resource.py Line 46 in 5594e82 response = requests.get(endpoint, **options) The use of "requests" component library on a multi-thread context with a large number of concurrent threads requests data to Clearbit Se...
Open Graph Description: clearbit-python/clearbit/resource.py Line 46 in 5594e82 response = requests.get(endpoint, **options) The use of "requests" component library on a multi-thread context with a large number of concurr...
X Description: clearbit-python/clearbit/resource.py Line 46 in 5594e82 response = requests.get(endpoint, **options) The use of "requests" component library on a multi-thread context with a large number ...
Opengraph URL: https://github.com/clearbit/clearbit-python/issues/35
X: @github
Domain: patch-diff.githubusercontent.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"On a multi-thread context, the use of this method could lead to \"HTTPSConnectionPool ... Max retries exceeded with url...\"","articleBody":"https://github.com/clearbit/clearbit-python/blob/5594e824663b8aaa615e1ec15af61d309239716a/clearbit/resource.py#L46\r\n\r\nThe use of \"requests\" component library on a multi-thread context with a large number of concurrent threads requests data to Clearbit Servers, as an example, using the Reveal API to find company data by IP. We could got an error from server. But, this is not an issue on server side, because server has a limit and this is fine. The problem is how to handle this issue on client side.\r\n\r\nSo, I made an improve on my own using the code below:\r\n\r\n_A little brief on this code: Find company by IP._\r\n\r\nTo highlight the improvement, the code add a Retry strategy to handle issues when the server returns the status code [429, 500, 502, 503, 504. Just remembering that this is from my case, we should refactor this using a factory + configuration design model to avoid hardocoded configuration on this end.\r\n\r\n```python\r\n\r\n@staticmethod\r\ndef __createSession__():\r\n session = requests.Session()\r\n retry = Retry(\r\n total=3,\r\n backoff_factor=1,\r\n status_forcelist=[429, 500, 502, 503, 504],\r\n method_whitelist=[\"HEAD\", \"GET\", \"OPTIONS\"]\r\n )\r\n adapter = HTTPAdapter(max_retries=retry)\r\n session.mount('http://', adapter)\r\n session.mount('https://', adapter)\r\n return session\r\n\r\n\r\n def findCompanyInfoByIp(self, ip: string) -\u003e ClearbitResult:\r\n if ip is None or ip == \"\":\r\n return ErrorClearbitResult(f\"Can't find clearbit data with a valid ip\")\r\n url = f\"{BASE_URL}/find?ip={urllib.parse.quote(ip)}\"\r\n try:\r\n response = \\\r\n self.__requestSession.get(\r\n url,\r\n auth=BearerAuth(self.__authToken))\r\n return ClearbitResult(response)\r\n except Exception as e:\r\n errorMessage = f\"Error requesting Clearbit at [{url}]: {e}\"\r\n self.__logger.error(errorMessage)\r\n return ErrorClearbitResult(errorMessage)\r\n```\r\n\r\nThis solution helps me to ensure 100 or maybe more threands to requests Clearbit Reveal API using a simple retry strategy.\r\n\r\nCould this be an improvement to help this library?","author":{"url":"https://github.com/fabiofalavinha","@type":"Person","name":"fabiofalavinha"},"datePublished":"2021-09-13T12:51:26.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":0},"url":"https://github.com/35/clearbit-python/issues/35"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:b0bfc2fd-fa78-441f-b39c-c3accc52c6e8 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C5C4:3C057:27EA4E:36BDE9:6981F234 |
| html-safe-nonce | 68f72d1492ab28b886cdca398c468457b51159b0cb0f129192332fe71a540c36 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDNUM0OjNDMDU3OjI3RUE0RTozNkJERTk6Njk4MUYyMzQiLCJ2aXNpdG9yX2lkIjoiMzU3OTcwNDg0MTgyMTM1MjUwMCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | a2844ee3055ef9c9c945ffabdc84ab1b743d37d30a6b1fee3563bed56a352809 |
| hovercard-subject-tag | issue:994852686 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/clearbit/clearbit-python/35/issue_layout |
| twitter:image | https://opengraph.githubassets.com/6a97d89c6fd014c926aa0b567f7174f693a8da9129be56558128ebfb8a93d77a/clearbit/clearbit-python/issues/35 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/6a97d89c6fd014c926aa0b567f7174f693a8da9129be56558128ebfb8a93d77a/clearbit/clearbit-python/issues/35 |
| og:image:alt | clearbit-python/clearbit/resource.py Line 46 in 5594e82 response = requests.get(endpoint, **options) The use of "requests" component library on a multi-thread context with a large number of concurr... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | fabiofalavinha |
| hostname | github.com |
| expected-hostname | github.com |
| None | ebfdf8d3e0fd17b103f41cc6696d84938694ebebdfecaf11fe00dbe4a9785801 |
| turbo-cache-control | no-preview |
| go-import | github.com/clearbit/clearbit-python git https://github.com/clearbit/clearbit-python.git |
| octolytics-dimension-user_id | 9300813 |
| octolytics-dimension-user_login | clearbit |
| octolytics-dimension-repository_id | 27684447 |
| octolytics-dimension-repository_nwo | clearbit/clearbit-python |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 27684447 |
| octolytics-dimension-repository_network_root_nwo | clearbit/clearbit-python |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | ac4541b58a15c144d6ed4fc868b9ea4bb99bb4b6 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width