[问题] thread error

楼主: kennykobe (凯尼狗鼻哥)   2021-04-12 22:03:24
from threading import Thread
import requests
import time
def status200():
res_200 = requests.get('url').status_code
def status301():
res_301 = requests.get('url', allow_redirects=False).status_code
def status502():
try:
res_502 = requests.get('url', timeout=3).status_code
except requests.exceptions.Timeout:
print('Timeout')
except requests.exceptions.ConnectionError:
print ("Error Connecting")
except requests.exceptions.RequestException as e:
raise SystemExit(e)
for i in range(150):
t1 = Thread(target=status200)
t1.start()
t2 = Thread(target=status301)
t2.start()
t3 = Thread(target=status502)
t3.start()
程式模拟同时对三个站送出requests,总共会有450个requests
跑下去会出现底下错误(错误讯息有点长,截取部分)
exception in thread thread-277:
socket.gaierror: [errno 8] nodename nor servname provided, or not known
同时并发450个请求,感觉也不是很大
请各位大大帮忙看看,感谢

Links booklink

Contact Us: admin [ a t ] ucptt.com