Skip to content

Commit

Permalink
kwargs in requests
Browse files Browse the repository at this point in the history
好方便啊
  • Loading branch information
yjqiang committed Apr 9, 2019
1 parent 215a879 commit cff028a
Showing 1 changed file with 7 additions and 13 deletions.
20 changes: 7 additions & 13 deletions web_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,17 @@ async def __get_binary_body(self, rsp):
async def request_json(self,
method,
url,
headers=None,
data=None,
params=None,
is_login=False,
ctrl: Ctrl = TMP_DEFAULT_CTRL)->dict:
ctrl: Ctrl = TMP_DEFAULT_CTRL,
**kwargs) -> dict:
async with sem:
i = 0
while True:
i += 1
if i >= 10:
printer.warn(url)
try:
async with self.var_session.request(method, url, headers=headers, data=data, params=params) as rsp:
async with self.var_session.request(method, url, **kwargs) as rsp:
if rsp.status == 200:
json_body = await self.__get_json_body(rsp)
if not json_body: # 有时候是None或空,直接屏蔽。下面的read/text类似,禁止返回空的东西
Expand Down Expand Up @@ -72,17 +70,15 @@ async def request_json(self,
async def request_binary(self,
method,
url,
headers=None,
data=None,
params=None)->bytes:
**kwargs) -> bytes:
async with sem:
i = 0
while True:
i += 1
if i >= 10:
printer.warn(url)
try:
async with self.var_session.request(method, url, headers=headers, data=data, params=params) as rsp:
async with self.var_session.request(method, url, **kwargs) as rsp:
if rsp.status == 200:
binary_body = await self.__get_binary_body(rsp)
if binary_body:
Expand All @@ -98,17 +94,15 @@ async def request_binary(self,
async def request_text(self,
method,
url,
headers=None,
data=None,
params=None)->str:
**kwargs) -> str:
async with sem:
i = 0
while True:
i += 1
if i >= 10:
printer.warn(url)
try:
async with self.var_session.request(method, url, headers=headers, data=data, params=params) as rsp:
async with self.var_session.request(method, url, **kwargs) as rsp:
if rsp.status == 200:
text_body = await self.__get_text_body(rsp)
if text_body:
Expand Down

0 comments on commit cff028a

Please sign in to comment.