add timeout
This commit is contained in:
1 parent
d57d7596fa
commit
07d7817137
1 file changed
+3
-3
+3
-3
@@ -17,7 +17,7 @@ class htmlUtils:
|
|||||||
#数据为空则获取数据
|
#数据为空则获取数据
|
||||||
if url_text == None:
|
if url_text == None:
|
||||||
print("请求地址:",curl)
|
print("请求地址:",curl)
|
||||||
res = requests.get(curl, headers=cls.headers)
|
res = requests.get(curl, headers=cls.headers, timeout=(10,15))
|
||||||
url_text = html.fromstring(res.text)
|
url_text = html.fromstring(res.text)
|
||||||
data = { curl : url_text}
|
data = { curl : url_text}
|
||||||
cls.url_data.update(data)
|
cls.url_data.update(data)
|
||||||
@@ -25,11 +25,11 @@ class htmlUtils:
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def getBytes(cls, url):
|
def getBytes(cls, url):
|
||||||
return requests.get(url, headers=cls.headers,stream=True)
|
return requests.get(url, headers=cls.headers,stream=True,timeout=(10,15))
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def getJSON(cls,curl):
|
def getJSON(cls,curl):
|
||||||
res = requests.get(curl, headers=cls.headers)
|
res = requests.get(curl, headers=cls.headers,timeout=(10,15))
|
||||||
data_json = res.json()
|
data_json = res.json()
|
||||||
return data_json
|
return data_json
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user