Skip to content

Commit

Permalink
fix requests session stream
Browse files Browse the repository at this point in the history
  • Loading branch information
jxxghp committed Oct 6, 2023
1 parent 5bcd90c commit 2ee477c
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions app/utils/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,17 @@ def post(self, url: str, data: Any = None, json: dict = None) -> Optional[Respon
headers=self._headers,
proxies=self._proxies,
timeout=self._timeout,
json=json)
json=json,
stream=False)
else:
return requests.post(url,
data=data,
verify=False,
headers=self._headers,
proxies=self._proxies,
timeout=self._timeout,
json=json)
json=json,
stream=False)
except requests.exceptions.RequestException:
return None

Expand Down Expand Up @@ -109,7 +111,8 @@ def get_res(self, url: str,
proxies=self._proxies,
cookies=self._cookies,
timeout=self._timeout,
allow_redirects=allow_redirects)
allow_redirects=allow_redirects,
stream=False)
else:
return requests.get(url,
params=params,
Expand All @@ -120,7 +123,8 @@ def get_res(self, url: str,
proxies=self._proxies,
cookies=self._cookies,
timeout=self._timeout,
allow_redirects=allow_redirects)
allow_redirects=allow_redirects,
stream=False)
except requests.exceptions.RequestException:
if raise_exception:
raise requests.exceptions.RequestException
Expand All @@ -129,7 +133,8 @@ def get_res(self, url: str,
def post_res(self, url: str, data: Any = None, params: dict = None,
allow_redirects: bool = True,
files: Any = None,
json: dict = None) -> Optional[Response]:
json: dict = None,
raise_exception: bool = False) -> Optional[Response]:
try:
if self._session:
return self._session.post(url,
Expand All @@ -142,7 +147,8 @@ def post_res(self, url: str, data: Any = None, params: dict = None,
timeout=self._timeout,
allow_redirects=allow_redirects,
files=files,
json=json)
json=json,
stream=False)
else:
return requests.post(url,
data=data,
Expand All @@ -154,8 +160,11 @@ def post_res(self, url: str, data: Any = None, params: dict = None,
timeout=self._timeout,
allow_redirects=allow_redirects,
files=files,
json=json)
json=json,
stream=False)
except requests.exceptions.RequestException:
if raise_exception:
raise requests.exceptions.RequestException
return None

@staticmethod
Expand Down

0 comments on commit 2ee477c

Please sign in to comment.