Python errno.ECONNRESET Examples
The following are 30
code examples of errno.ECONNRESET().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
errno
, or try the search function
.
Example #1
Source File: test_http.py From cherrypy with BSD 3-Clause "New" or "Revised" License | 6 votes |
def test_garbage_in(self): # Connect without SSL regardless of server.scheme c = HTTPConnection('%s:%s' % (self.interface(), self.PORT)) c._output(b'gjkgjklsgjklsgjkljklsg') c._send_output() response = c.response_class(c.sock, method='GET') try: response.begin() self.assertEqual(response.status, 400) self.assertEqual(response.fp.read(22), b'Malformed Request-Line') c.close() except socket.error: e = sys.exc_info()[1] # "Connection reset by peer" is also acceptable. if e.errno != errno.ECONNRESET: raise
Example #2
Source File: DNRelay.py From rtp_cluster with BSD 2-Clause "Simplified" License | 6 votes |
def deliver_dnotify(self, dnstring, _recurse = 0): if self.s == None: self.connect() if _recurse > _MAX_RECURSE: raise Exception('Cannot reconnect: %s', self.spath) if not dnstring.endswith('\n'): dnstring += '\n' while True: try: self.s.send(dnstring) break except socket.error as why: if why[0] == EINTR: continue elif why[0] in (EPIPE, ENOTCONN, ECONNRESET): self.s = None return self.deliver_dnotify(dnstring, _recurse + 1) raise why # Clean any incoming data on the socket if len(self.poller.poll(0)) > 0: try: self.s.recv(1024) except: pass return
Example #3
Source File: xmlrpclib.py From BinderFilter with MIT License | 6 votes |
def request(self, host, handler, request_body, verbose=0): #retry request once if cached connection has gone cold for i in (0, 1): try: return self.single_request(host, handler, request_body, verbose) except socket.error, e: if i or e.errno not in (errno.ECONNRESET, errno.ECONNABORTED, errno.EPIPE): raise except httplib.BadStatusLine: #close after we sent request if i: raise ## # Send a complete request, and parse the response. # # @param host Target host. # @param handler Target PRC handler. # @param request_body XML-RPC request body. # @param verbose Debugging flag. # @return Parsed response.
Example #4
Source File: xmlrpclib.py From meddle with MIT License | 6 votes |
def request(self, host, handler, request_body, verbose=0): #retry request once if cached connection has gone cold for i in (0, 1): try: return self.single_request(host, handler, request_body, verbose) except socket.error, e: if i or e.errno not in (errno.ECONNRESET, errno.ECONNABORTED, errno.EPIPE): raise except httplib.BadStatusLine: #close after we sent request if i: raise ## # Send a complete request, and parse the response. # # @param host Target host. # @param handler Target PRC handler. # @param request_body XML-RPC request body. # @param verbose Debugging flag. # @return Parsed response.
Example #5
Source File: hls.py From crunchy-xml-decoder with GNU General Public License v2.0 | 6 votes |
def read(self, n): buffer = [] while self.offset < self.file_size: try: data = self.stream.read(min(n, self.file_size - self.offset)) self.offset += len(data) n -= len(data) buffer.append(data) if n == 0 or data: break except socket.timeout: self._progress() self._restart() except socket.error as e: if e.errno != errno.ECONNRESET: raise self._progress() self._restart() return "".join(buffer)
Example #6
Source File: xmlrpclib.py From ironpython2 with Apache License 2.0 | 6 votes |
def request(self, host, handler, request_body, verbose=0): #retry request once if cached connection has gone cold for i in (0, 1): try: return self.single_request(host, handler, request_body, verbose) except socket.error, e: if i or e.errno not in (errno.ECONNRESET, errno.ECONNABORTED, errno.EPIPE): raise except httplib.BadStatusLine: #close after we sent request if i: raise ## # Send a complete request, and parse the response. # # @param host Target host. # @param handler Target PRC handler. # @param request_body XML-RPC request body. # @param verbose Debugging flag. # @return Parsed response.
Example #7
Source File: xmlrpclib.py From oss-ftp with MIT License | 6 votes |
def request(self, host, handler, request_body, verbose=0): #retry request once if cached connection has gone cold for i in (0, 1): try: return self.single_request(host, handler, request_body, verbose) except socket.error, e: if i or e.errno not in (errno.ECONNRESET, errno.ECONNABORTED, errno.EPIPE): raise except httplib.BadStatusLine: #close after we sent request if i: raise ## # Send a complete request, and parse the response. # # @param host Target host. # @param handler Target PRC handler. # @param request_body XML-RPC request body. # @param verbose Debugging flag. # @return Parsed response.
Example #8
Source File: sync.py From jbox with MIT License | 5 votes |
def handle(self, listener, client, addr): req = None try: if self.cfg.is_ssl: client = ssl.wrap_socket(client, server_side=True, **self.cfg.ssl_options) parser = http.RequestParser(self.cfg, client) req = six.next(parser) self.handle_request(listener, req, client, addr) except http.errors.NoMoreData as e: self.log.debug("Ignored premature client disconnection. %s", e) except StopIteration as e: self.log.debug("Closing connection. %s", e) except ssl.SSLError as e: if e.args[0] == ssl.SSL_ERROR_EOF: self.log.debug("ssl connection closed") client.close() else: self.log.debug("Error processing SSL request.") self.handle_error(req, client, addr, e) except EnvironmentError as e: if e.errno not in (errno.EPIPE, errno.ECONNRESET): self.log.exception("Socket error processing request.") else: if e.errno == errno.ECONNRESET: self.log.debug("Ignoring connection reset") else: self.log.debug("Ignoring EPIPE") except Exception as e: self.handle_error(req, client, addr, e) finally: util.close(client)
Example #9
Source File: Rtp_proxy_client_stream.py From rtp_cluster with BSD 2-Clause "Simplified" License | 5 votes |
def send_raw(self, command, _recurse = 0, stime = None): if _recurse > _MAX_RECURSE: raise Exception('Cannot reconnect: %s' % (str(self.userv.address),)) if self.s == None: self.connect() #print('%s.send_raw(%s)' % (id(self), command)) if stime == None: stime = MonoTime() while True: try: self.s.send(command.encode()) break except socket.error as why: if why.errno == EINTR: continue elif why.errno in (EPIPE, ENOTCONN, ECONNRESET): self.s = None return self.send_raw(command, _recurse + 1, stime) raise why while True: try: rval = self.s.recv(1024) if len(rval) == 0: self.s = None return self.send_raw(command, _MAX_RECURSE, stime) rval = rval.decode().strip() break except socket.error as why: if why.errno == EINTR: continue elif why.errno in (EPIPE, ENOTCONN, ECONNRESET): self.s = None return self.send_raw(command, _recurse + 1, stime) raise why rtpc_delay = stime.offsetFromNow() return (rval, rtpc_delay)
Example #10
Source File: roomgraph.py From abusehelper with MIT License | 5 votes |
def _recvall_blocking(conn, amount): data = [] while amount > 0: with wrapped_socket_errnos(errno.ECONNRESET): piece = conn.recv(amount) if not piece: raise _ConnectionLost("could not recv() all bytes") data.append(piece) amount -= len(piece) return "".join(data)
Example #11
Source File: iostream.py From tornado-zh with MIT License | 5 votes |
def _is_connreset(self, exc): """Return true if exc is ECONNRESET or equivalent. May be overridden in subclasses. """ return (isinstance(exc, (socket.error, IOError)) and errno_from_exception(exc) in _ERRNO_CONNRESET)
Example #12
Source File: iostream.py From tornado-zh with MIT License | 5 votes |
def _read_to_buffer(self): """Reads from the socket and appends the result to the read buffer. Returns the number of bytes read. Returns 0 if there is nothing to read (i.e. the read returns EWOULDBLOCK or equivalent). On error closes the socket and raises an exception. """ while True: try: chunk = self.read_from_fd() except (socket.error, IOError, OSError) as e: if errno_from_exception(e) == errno.EINTR: continue # ssl.SSLError is a subclass of socket.error if self._is_connreset(e): # Treat ECONNRESET as a connection close rather than # an error to minimize log spam (the exception will # be available on self.error for apps that care). self.close(exc_info=True) return self.close(exc_info=True) raise break if chunk is None: return 0 self._read_buffer.append(chunk) self._read_buffer_size += len(chunk) if self._read_buffer_size > self.max_buffer_size: gen_log.error("Reached maximum read buffer size") self.close() raise StreamBufferFullError("Reached maximum read buffer size") return len(chunk)
Example #13
Source File: iostream.py From tornado-zh with MIT License | 5 votes |
def _is_connreset(self, exc): """Return true if exc is ECONNRESET or equivalent. May be overridden in subclasses. """ return (isinstance(exc, (socket.error, IOError)) and errno_from_exception(exc) in _ERRNO_CONNRESET)
Example #14
Source File: client.py From verge3d-blender-addon with GNU General Public License v3.0 | 5 votes |
def request(self, host, handler, request_body, verbose=False): #retry request once if cached connection has gone cold for i in (0, 1): try: return self.single_request(host, handler, request_body, verbose) except socket.error as e: if i or e.errno not in (errno.ECONNRESET, errno.ECONNABORTED, errno.EPIPE): raise except http_client.BadStatusLine: #close after we sent request if i: raise
Example #15
Source File: iostream.py From tornado-zh with MIT License | 5 votes |
def _read_to_buffer(self): """Reads from the socket and appends the result to the read buffer. Returns the number of bytes read. Returns 0 if there is nothing to read (i.e. the read returns EWOULDBLOCK or equivalent). On error closes the socket and raises an exception. """ while True: try: chunk = self.read_from_fd() except (socket.error, IOError, OSError) as e: if errno_from_exception(e) == errno.EINTR: continue # ssl.SSLError is a subclass of socket.error if self._is_connreset(e): # Treat ECONNRESET as a connection close rather than # an error to minimize log spam (the exception will # be available on self.error for apps that care). self.close(exc_info=True) return self.close(exc_info=True) raise break if chunk is None: return 0 self._read_buffer.append(chunk) self._read_buffer_size += len(chunk) if self._read_buffer_size > self.max_buffer_size: gen_log.error("Reached maximum read buffer size") self.close() raise StreamBufferFullError("Reached maximum read buffer size") return len(chunk)
Example #16
Source File: roomgraph.py From abusehelper with MIT License | 5 votes |
def _recvall_stream(sock, amount, timeout=None): data = [] while amount > 0: with wrapped_socket_errnos(errno.ECONNRESET): piece = yield sock.recv(amount, timeout=timeout) if not piece: raise _ConnectionLost("could not recv() all bytes") data.append(piece) amount -= len(piece) idiokit.stop("".join(data))
Example #17
Source File: roomgraph.py From abusehelper with MIT License | 5 votes |
def send_encoded(conn, obj): msg_bytes = cPickle.dumps(obj, cPickle.HIGHEST_PROTOCOL) data = struct.pack("!I", len(msg_bytes)) + msg_bytes with wrapped_socket_errnos(errno.ECONNRESET, errno.EPIPE): conn.sendall(data)
Example #18
Source File: ustreamtv.py From streamlink with BSD 2-Clause "Simplified" License | 5 votes |
def run(self): while not self.stopped.wait(0): try: cmd_args = self.api.recv() except (SocketError, websocket._exceptions.WebSocketConnectionClosedException) as err: cmd_args = None if (hasattr(err, "errno") and err.errno in (errno.ECONNRESET, errno.ETIMEDOUT) or "Connection is already closed." in str(err)): while True: # --stream-timeout will handle the timeout try: # reconnect on network issues self.api.reconnect() break except websocket._exceptions.WebSocketAddressException: # no connection available reconnect_time_ws = 5 log.error("Local network issue, websocket reconnecting in {0}s".format(reconnect_time_ws)) sleep(reconnect_time_ws) else: raise except PluginError: continue if not cmd_args: continue if cmd_args["cmd"] == "warning": log.warning("{code}: {message}", **cmd_args["args"]) if cmd_args["cmd"] == "moduleInfo": data = self.handle_module_info(cmd_args["args"]) if data: self.data_chunks.append(data) log.debug("Stopped API polling")
Example #19
Source File: test_ssl.py From BinderFilter with MIT License | 5 votes |
def try_protocol_combo(server_protocol, client_protocol, expect_success, certsreqs=None): if certsreqs is None: certsreqs = ssl.CERT_NONE certtype = { ssl.CERT_NONE: "CERT_NONE", ssl.CERT_OPTIONAL: "CERT_OPTIONAL", ssl.CERT_REQUIRED: "CERT_REQUIRED", }[certsreqs] if test_support.verbose: formatstr = (expect_success and " %s->%s %s\n") or " {%s->%s} %s\n" sys.stdout.write(formatstr % (ssl.get_protocol_name(client_protocol), ssl.get_protocol_name(server_protocol), certtype)) try: # NOTE: we must enable "ALL" ciphers, otherwise an SSLv23 client # will send an SSLv3 hello (rather than SSLv2) starting from # OpenSSL 1.0.0 (see issue #8322). server_params_test(CERTFILE, server_protocol, certsreqs, CERTFILE, CERTFILE, client_protocol, ciphers="ALL", chatty=False) # Protocol mismatch can result in either an SSLError, or a # "Connection reset by peer" error. except ssl.SSLError: if expect_success: raise except socket.error as e: if expect_success or e.errno != errno.ECONNRESET: raise else: if not expect_success: raise AssertionError( "Client protocol %s succeeded with server protocol %s!" % (ssl.get_protocol_name(client_protocol), ssl.get_protocol_name(server_protocol)))
Example #20
Source File: gthread.py From jbox with MIT License | 5 votes |
def handle(self, conn): keepalive = False req = None try: req = six.next(conn.parser) if not req: return (False, conn) # handle the request keepalive = self.handle_request(req, conn) if keepalive: return (keepalive, conn) except http.errors.NoMoreData as e: self.log.debug("Ignored premature client disconnection. %s", e) except StopIteration as e: self.log.debug("Closing connection. %s", e) except ssl.SSLError as e: if e.args[0] == ssl.SSL_ERROR_EOF: self.log.debug("ssl connection closed") conn.sock.close() else: self.log.debug("Error processing SSL request.") self.handle_error(req, conn.sock, conn.client, e) except EnvironmentError as e: if e.errno not in (errno.EPIPE, errno.ECONNRESET): self.log.exception("Socket error processing request.") else: if e.errno == errno.ECONNRESET: self.log.debug("Ignoring connection reset") else: self.log.debug("Ignoring connection epipe") except Exception as e: self.handle_error(req, conn.sock, conn.client, e) return (False, conn)
Example #21
Source File: test_ssl.py From ironpython2 with Apache License 2.0 | 5 votes |
def test_wrong_cert(self): """Connecting when the server rejects the client's certificate Launch a server with CERT_REQUIRED, and check that trying to connect to it with a wrong client certificate fails. """ certfile = os.path.join(os.path.dirname(__file__) or os.curdir, "keycert.pem") server = ThreadedEchoServer(SIGNED_CERTFILE, certreqs=ssl.CERT_REQUIRED, cacerts=SIGNING_CA, chatty=False, connectionchatty=False) with server, \ closing(socket.socket()) as sock, \ closing(ssl.wrap_socket(sock, certfile=certfile, ssl_version=ssl.PROTOCOL_TLSv1)) as s: try: # Expect either an SSL error about the server rejecting # the connection, or a low-level connection reset (which # sometimes happens on Windows) s.connect((HOST, server.port)) except ssl.SSLError as e: if support.verbose: sys.stdout.write("\nSSLError is %r\n" % e) except socket.error as e: if e.errno != errno.ECONNRESET: raise if support.verbose: sys.stdout.write("\nsocket.error is %r\n" % e) else: self.fail("Use of invalid cert should have failed!")
Example #22
Source File: TSocket.py From galaxy-sdk-python with Apache License 2.0 | 5 votes |
def read(self, sz): try: buff = self.handle.recv(sz) except socket.error, e: if (e.args[0] == errno.ECONNRESET and (sys.platform == 'darwin' or sys.platform.startswith('freebsd'))): # freebsd and Mach don't follow POSIX semantic of recv # and fail with ECONNRESET if peer performed shutdown. # See corresponding comment and code in TSocket::read() # in lib/cpp/src/transport/TSocket.cpp. self.close() # Trigger the check to raise the END_OF_FILE exception below. buff = '' else: raise
Example #23
Source File: hls.py From crunchy-xml-decoder with GNU General Public License v2.0 | 5 votes |
def _restart(self): req = urllib2.Request(self.uri) if self.offset: req.headers['Range'] = 'bytes=%s-' % (self.offset, ) while True: try: self.stream = urllib2.urlopen(req, timeout = 30) break except socket.timeout: continue except socket.error, e: if e.errno != errno.ECONNRESET: raise
Example #24
Source File: iostream.py From opendevops with GNU General Public License v3.0 | 5 votes |
def _is_connreset(self, exc: BaseException) -> bool: """Return ``True`` if exc is ECONNRESET or equivalent. May be overridden in subclasses. """ return ( isinstance(exc, (socket.error, IOError)) and errno_from_exception(exc) in _ERRNO_CONNRESET )
Example #25
Source File: test_ssl.py From oss-ftp with MIT License | 5 votes |
def wrap_conn(self): try: self.sslconn = self.server.context.wrap_socket( self.sock, server_side=True) self.server.selected_protocols.append(self.sslconn.selected_npn_protocol()) except socket.error as e: # We treat ConnectionResetError as though it were an # SSLError - OpenSSL on Ubuntu abruptly closes the # connection when asked to use an unsupported protocol. # # XXX Various errors can have happened here, for example # a mismatching protocol version, an invalid certificate, # or a low-level bug. This should be made more discriminating. if not isinstance(e, ssl.SSLError) and e.errno != errno.ECONNRESET: raise self.server.conn_errors.append(e) if self.server.chatty: handle_error("\n server: bad connection attempt from " + repr(self.addr) + ":\n") self.running = False self.server.stop() self.close() return False else: if self.server.context.verify_mode == ssl.CERT_REQUIRED: cert = self.sslconn.getpeercert() if support.verbose and self.server.chatty: sys.stdout.write(" client cert is " + pprint.pformat(cert) + "\n") cert_binary = self.sslconn.getpeercert(True) if support.verbose and self.server.chatty: sys.stdout.write(" cert binary is " + str(len(cert_binary)) + " bytes\n") cipher = self.sslconn.cipher() if support.verbose and self.server.chatty: sys.stdout.write(" server: connection cipher is now " + str(cipher) + "\n") sys.stdout.write(" server: selected protocol is now " + str(self.sslconn.selected_npn_protocol()) + "\n") return True
Example #26
Source File: web_control.py From oss-ftp with MIT License | 5 votes |
def finish_request(self, request, client_address): try: self.RequestHandlerClass(request, client_address, self) except NetWorkIOError as e: if e[0] not in (errno.ECONNABORTED, errno.ECONNRESET, errno.EPIPE): raise
Example #27
Source File: vthunder_per_tenant.py From a10-neutron-lbaas with Apache License 2.0 | 5 votes |
def get_a10_client(self, device_info, **kwargs): if kwargs.get('action', None) == 'create': retry = [errno.EHOSTUNREACH, errno.ECONNRESET, errno.ECONNREFUSED, errno.ETIMEDOUT] return acos_client.Client( device_info['host'], device_info['api_version'], device_info['username'], device_info['password'], port=device_info['port'], protocol=device_info['protocol'], retry_errno_list=retry) else: return super(VThunderPerTenantPlumbingHooks, self).get_a10_client(device_info, **kwargs)
Example #28
Source File: iostream.py From viewfinder with Apache License 2.0 | 5 votes |
def _read_to_buffer(self): """Reads from the socket and appends the result to the read buffer. Returns the number of bytes read. Returns 0 if there is nothing to read (i.e. the read returns EWOULDBLOCK or equivalent). On error closes the socket and raises an exception. """ try: chunk = self.read_from_fd() except (socket.error, IOError, OSError) as e: # ssl.SSLError is a subclass of socket.error if e.args[0] in _ERRNO_CONNRESET: # Treat ECONNRESET as a connection close rather than # an error to minimize log spam (the exception will # be available on self.error for apps that care). self.close(exc_info=True) return self.close(exc_info=True) raise if chunk is None: return 0 self._read_buffer.append(chunk) self._read_buffer_size += len(chunk) if self._read_buffer_size >= self.max_buffer_size: gen_log.error("Reached maximum read buffer size") self.close() raise IOError("Reached maximum read buffer size") return len(chunk)
Example #29
Source File: iostream.py From viewfinder with Apache License 2.0 | 5 votes |
def _read_to_buffer(self): """Reads from the socket and appends the result to the read buffer. Returns the number of bytes read. Returns 0 if there is nothing to read (i.e. the read returns EWOULDBLOCK or equivalent). On error closes the socket and raises an exception. """ try: chunk = self.read_from_fd() except (socket.error, IOError, OSError) as e: # ssl.SSLError is a subclass of socket.error if e.args[0] in _ERRNO_CONNRESET: # Treat ECONNRESET as a connection close rather than # an error to minimize log spam (the exception will # be available on self.error for apps that care). self.close(exc_info=True) return self.close(exc_info=True) raise if chunk is None: return 0 self._read_buffer.append(chunk) self._read_buffer_size += len(chunk) if self._read_buffer_size >= self.max_buffer_size: gen_log.error("Reached maximum read buffer size") self.close() raise IOError("Reached maximum read buffer size") return len(chunk)
Example #30
Source File: remote_pdb.py From python-remote-pdb with BSD 2-Clause "Simplified" License | 5 votes |
def set_trace(self, frame=None): if frame is None: frame = sys._getframe().f_back try: Pdb.set_trace(self, frame) except IOError as exc: if exc.errno != errno.ECONNRESET: raise