-
Notifications
You must be signed in to change notification settings - Fork 204
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace hardcoded session with http_client param
Remove timeout parameter, requests and httpx behaviors are incompatible anyway
- Loading branch information
Showing
3 changed files
with
92 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import requests | ||
|
||
|
||
class MinimalHttpClient: | ||
|
||
def __init__(self, verify=True, proxies=None, timeout=None): | ||
self.session = requests.Session() | ||
self.session.verify = verify | ||
self.session.proxies = proxies | ||
self.timeout = timeout | ||
|
||
def post(self, url, params=None, data=None, headers=None, **kwargs): | ||
return MinimalResponse(requests_resp=self.session.post( | ||
url, params=params, data=data, headers=headers, | ||
timeout=self.timeout)) | ||
|
||
def get(self, url, params=None, headers=None, **kwargs): | ||
return MinimalResponse(requests_resp=self.session.get( | ||
url, params=params, headers=headers, timeout=self.timeout)) | ||
|
||
|
||
class MinimalResponse(object): # Not for production use | ||
def __init__(self, requests_resp=None, status_code=None, text=None): | ||
self.status_code = status_code or requests_resp.status_code | ||
self.text = text or requests_resp.text | ||
self._raw_resp = requests_resp | ||
|
||
def raise_for_status(self): | ||
if self._raw_resp: | ||
self._raw_resp.raise_for_status() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters