HTTPConnectionPool(host='yzw.zjnu.edu.cn', port=80): Max retries exceeded with url: / (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 110] Connection timed out' ))
Traceback (most recent call last):
UnboundLocalError: local variable 'req' referenced before assignment
这是由于:能创建socket套接字句柄的数量是有限的,无论是win还是Linux,错误信息是用光了socket, 所以无法再建立tcp链接, 所以 要么sleep()停一下; 要么就让它不要一直保持着连接,访问完,完成一次传输就断掉 了。
添加一个请求头,请求头内字段为:
headers = {'Connection':'close'}
请求修改为:
res = requests.post('http://', json.dumps(data), headers=headers)
s = requests.session()
s.keep_alive = False