Traceback (most recent call last):
File "", line 1, in
File "D:\APP\pycharm\PyCharm 2018.2.1\helpers\pydev\_pydev_bundle\pydev_umd.py", line 194, in runfile
pydev_imports.execfile(filename, global_vars, local_vars) # execute the script
File "D:\APP\pycharm\PyCharm 2018.2.1\helpers\pydev\_pydev_imps\_pydev_execfile.py", line 18, in execfile
exec(compile(contents+"\n", file, 'exec'), glob, loc)
File "E:/azjp/python3/luxian_nforn.py", line 152, in
res_bus = urlopen(aurl_bus)
File "D:\python366\lib\urllib\request.py", line 223, in urlopen
return opener.open(url, data, timeout)
File "D:\python366\lib\urllib\request.py", line 526, in open
response = self._open(req, data)
File "D:\python366\lib\urllib\request.py", line 544, in _open
'_open', req)
File "D:\python366\lib\urllib\request.py", line 504, in _call_chain
result = func(*args)
File "D:\python366\lib\urllib\request.py", line 1346, in http_open
return self.do_open(http.client.HTTPConnection, req)
File "D:\python366\lib\urllib\request.py", line 1321, in do_open
r = h.getresponse()
File "D:\python366\lib\http\client.py", line 1331, in getresponse
response.begin()
File "D:\python366\lib\http\client.py", line 297, in begin
version, status, reason = self._read_status()
File "D:\python366\lib\http\client.py", line 258, in _read_status
line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
File "D:\python366\lib\socket.py", line 586, in readinto
return self._sock.recv_into(b)
ConnectionResetError: [WinError 10054] 远程主机强迫关闭了一个现有的连接。
分析原因,可能是因为使用urlopen打开网页太过频繁,引起远程主机的怀疑,被认定为是攻击行为。导致执行urlopen()后,request. read()一直卡死在那里,最后抛出异常。
这个错误是connection reset by peer.也就是传说的远端主机重置了此连接。原因可能是socket超时时间过长;request = urllib.request.urlopen(url)之后,没有进行request.close()操作;无sleep间隔,导致网站认定这种行为是攻击。