Python套接字ConnectionResetError:[Errno 54] peer vs socket.error重置连接:[Errno 104] peer by peer reset

时间:2015-03-26 04:02:08

标签: python sockets urllib errno

我无法调试代码,因为我无法理解引发的套接字错误。 这是追溯。

Traceback (most recent call last):
 File "clickpression.py", line 517, in <module> presser.main()
 File "clickpression.py", line 391, in main
 File "clickpression.py", line 121, in clickpress self.refresh_proxies(country=country)
 File "clickpression.py", line 458, in refresh_proxies self.proxies = self.get_proxies(country=country)
 File "helpers.py", line 72, in wrapper return func(*args, **kwargs)
 File "clickpression.py", line 264, in get_proxies self.settings.SUPER_PROXY).read().decode('utf-8')
 File "/usr/local/Cellar/python3/3.4.3/Frameworks/Python.framework/Versions/3.4/lib/python3.4/urllib/request.py", line 161, in urlopen return opener.open(url, data, timeout)
 File "/usr/local/Cellar/python3/3.4.3/Frameworks/Python.framework/Versions/3.4/lib/python3.4/urllib/request.py", line 463, in open response = self._open(req, data)
 File "/usr/local/Cellar/python3/3.4.3/Frameworks/Python.framework/Versions/3.4/lib/python3.4/urllib/request.py", line 481, in _open '_open', req)
 File "/usr/local/Cellar/python3/3.4.3/Frameworks/Python.framework/Versions/3.4/lib/python3.4/urllib/request.py", line 441, in _call_chain result = func(*args)
 File "/usr/local/Cellar/python3/3.4.3/Frameworks/Python.framework/Versions/3.4/lib/python3.4/urllib/request.py", line 1210, in http_open return self.do_open(http.client.HTTPConnection, req)
 File "/usr/local/Cellar/python3/3.4.3/Frameworks/Python.framework/Versions/3.4/lib/python3.4/urllib/request.py", line 1185, in do_open r = h.getresponse()
 File "/usr/local/Cellar/python3/3.4.3/Frameworks/Python.framework/Versions/3.4/lib/python3.4/http/client.py", line 1171, in getresponse response.begin()
 File "/usr/local/Cellar/python3/3.4.3/Frameworks/Python.framework/Versions/3.4/lib/python3.4/http/client.py", line 351, in begin version, status, reason = self._read_status()
 File "/usr/local/Cellar/python3/3.4.3/Frameworks/Python.framework/Versions/3.4/lib/python3.4/http/client.py", line 313, in _read_status line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
 File "/usr/local/Cellar/python3/3.4.3/Frameworks/Python.framework/Versions/3.4/lib/python3.4/socket.py", line 374, in readinto return self._sock.recv_into(b)
ConnectionResetError: [Errno 54] Connection reset by peer

根据errnoErrno 54errno.EXFULL,其中py {3} documentation被解释为exchange full

据我了解,Connection reset by peerErrno 104,即errno.ECONNRESET

那么errno.EXFULL意味着什么?为什么套接字使用connection reset by peer描述而不是exchange full来引发错误。或者两个错误errno.EXFULLerrno.ECONNRESET如何相关?

PS:我read errno 54可能与http代理有关(我在我的代码中使用代理)。如果是这样,怎么样?

3 个答案:

答案 0 :(得分:0)

  

根据errnoErrno 54errno.EXFULL

您是否通过检查errno.errorcode[54]来确定?无论如何 - 这个 errno可能有问题。您可以通过查看errno.h来验证系统上错误代码的含义。 G。在gcc的帮助下:

gcc -xc -imacros errno.h -Wp,-P -E <(echo ECONNRESET)

此外,Python documentation说:

  

要将数字错误代码转换为错误消息,请使用   os.strerror()。

您的系统上的错误编号54可能是ECONNRESET,而os.strerror(54)会证明错误。

既然您已经确认os.strerror(54)返回“Exchange已满”,我很困惑为什么错误号54和错误字符串Connection reset by peer不匹配。如果在strace或类似的系统上发生这种情况,我会进一步检查操作系统通过在受影响的进程上使用strace -e network返回哪个错误。

关于你关于EXFULL的问题:它的含义似乎有点依赖于系统;即G。在Linux上,EXFULL只从内核中的少数几个地方返回,这是与网桥相关的唯一与网络相关的地方,当没有找到可用的桥接端口号时(其他地方在USB和SCSI驱动程序中)

答案 1 :(得分:0)

我试图使用WebSocket在OKEX.com上使用python来筹集硬币市场,因为url是外部地址,我使用了我们提供的vpn服务,但仍然可以使用。这是追溯代码。

from ws4py.client.threadedclient import WebSocketClient


class DummyClient(WebSocketClient):
    def opened(self):
      # self.send("{'event': 'addChannel', 'channel': 'ok_sub_futureusd_btc_ticker_this_week'}") #发送请求数据格式
         # self.send("www.baidu.com")
         self.send("{'event':'addChannel','channel':'ok_sub_spot_bch_btc_ticker'}")
    def closed(self, code, reason=None):
        print("Closed down", code, reason)

#服务器返回消息
    def received_message(self, m):
        print("recv:", m)


if __name__ == '__main__':

    try:
        # 服务器连接地址wss://real.okex.com:10440/websocket/okexapi
       # ws = DummyClient('wss://real.okcoin.cn:10440/websocket/okcoinapi', protocols=['chat'])
        ws = DummyClient('wss://real.okex.com:10440/websocket/okexapi', protocols=['chat'])
        ws.connect()
        #ws.send("my test...")
        ws.run_forever()
    except KeyboardInterrupt:
        ws.close()

enter image description here

答案 2 :(得分:-1)

您可以在项目中尝试此代码:

import ssl
ssl._create_default_https_context = ssl._create_unverified_context

如果不起作用,请确保服务器打开TLSv1支持。