Skip to content

Commit

Permalink
优化request效率
Browse files Browse the repository at this point in the history
  • Loading branch information
Boris-code committed Jun 24, 2021
1 parent b3e2ac1 commit 0561b54
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions feapder/network/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class Request(object):
local_filepath = None
oss_handler = None

__REQUEST_ATTRS__ = [
__REQUEST_ATTRS__ = {
# 'method', 'url', 必须传递 不加入**kwargs中
"params",
"data",
Expand All @@ -55,7 +55,7 @@ class Request(object):
"verify",
"cert",
"json",
]
}

DEFAULT_KEY_VALUE = dict(
url="",
Expand Down Expand Up @@ -247,7 +247,9 @@ def get_response(self, save_cached=False):
@return:
"""
# 设置超时默认时间
self.requests_kwargs.setdefault("timeout", setting.REQUEST_TIMEOUT) # connect=22 read=22
self.requests_kwargs.setdefault(
"timeout", setting.REQUEST_TIMEOUT
) # connect=22 read=22

# 设置stream
# 默认情况下,当你进行网络请求后,响应体会立即被下载。你可以通过 stream 参数覆盖这个行为,推迟下载响应体直到访问 Response.content 属性。此时仅有响应头被下载下来了。缺点: stream 设为 True,Requests 无法将连接释放回连接池,除非你 消耗了所有的数据,或者调用了 Response.close。 这样会带来连接效率低下的问题。
Expand Down

0 comments on commit 0561b54

Please sign in to comment.