Python urllib3.exceptions.NewConnectionError() Examples
The following are 18
code examples of urllib3.exceptions.NewConnectionError().
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
urllib3.exceptions
, or try the search function
.
Example #1
Source File: simple_requests_client.py From py-stellar-base with Apache License 2.0 | 7 votes |
def post(self, url: str, data: Dict[str, str]) -> Response: """Perform HTTP POST request. :param url: the request url :param data: the data send to server :return: the response from server :raise: :exc:`ConnectionError <stellar_sdk.exceptions.ConnectionError>` """ try: resp = requests.post(url=url, data=data, headers=HEADERS) except (RequestException, NewConnectionError) as err: raise ConnectionError(err) return Response( status_code=resp.status_code, text=resp.text, headers=dict(resp.headers), url=resp.url, )
Example #2
Source File: targetinfo.py From SlowLoris with MIT License | 6 votes |
def get_info(self): if not self.is_checked: try: r = requests.get(str(self), timeout=(10, 3)) if r.status_code == 200: self.server = r.headers['Server'] elif r.status_code >= 400: raise TargetNotExistException(self.url) except requests.exceptions.ReadTimeout as rt: logger.exception(rt) try: url = re.compile(r"https?://(www\.)?") self.url_c = url.sub('', self.url).strip().strip('/') self.ip = socket.gethostbyname(self.url_c) except socket.gaierror as err: logger.exception(err) except NewConnectionError: raise TargetNotExistException(self.url) self.is_checked = True
Example #3
Source File: adapter.py From torpy with Apache License 2.0 | 6 votes |
def connect(self): logger.debug('[MyHTTPConnection] connect %s:%i', self.host, self.port) try: self._tor_stream = self._circuit.create_stream((self.host, self.port)) logger.debug('[MyHTTPConnection] tor_stream create_socket') self.sock = self._tor_stream.create_socket() if self._tunnel_host: self._tunnel() except TimeoutError: logger.error('TimeoutError') raise ConnectTimeoutError( self, 'Connection to %s timed out. (connect timeout=%s)' % (self.host, self.timeout) ) except Exception as e: logger.error('NewConnectionError') raise NewConnectionError(self, 'Failed to establish a new connection: %s' % e)
Example #4
Source File: requests_client.py From py-stellar-base with Apache License 2.0 | 6 votes |
def post(self, url: str, data: Dict[str, str] = None) -> Response: """Perform HTTP POST request. :param url: the request url :param data: the data send to server :return: the response from server :raise: :exc:`ConnectionError <stellar_sdk.exceptions.ConnectionError>` """ try: resp = self._session.post(url, data=data, timeout=self.post_timeout) except (RequestException, NewConnectionError) as err: raise ConnectionError(err) return Response( status_code=resp.status_code, text=resp.text, headers=dict(resp.headers), url=resp.url, )
Example #5
Source File: requests_client.py From py-stellar-base with Apache License 2.0 | 6 votes |
def get(self, url: str, params: Dict[str, str] = None) -> Response: """Perform HTTP GET request. :param url: the request url :param params: the request params :return: the response from server :raise: :exc:`ConnectionError <stellar_sdk.exceptions.ConnectionError>` """ try: resp = self._session.get(url, params=params, timeout=self.request_timeout) except (RequestException, NewConnectionError) as err: raise ConnectionError(err) return Response( status_code=resp.status_code, text=resp.text, headers=dict(resp.headers), url=resp.url, )
Example #6
Source File: client.py From kube-shell with Apache License 2.0 | 6 votes |
def get_resource(self, resource, namespace="all"): ret, resources = None, list() try: ret, namespaced_resource = self._call_api_client(resource) except ApiException as ae: self.logger.warning("resource autocomplete disabled, encountered " "ApiException", exc_info=1) except (NewConnectionError, MaxRetryError, ConnectTimeoutError): self.logger.warning("unable to connect to k8 cluster", exc_info=1) if ret: for i in ret.items: if namespace == "all" or not namespaced_resource: resources.append((i.metadata.name, i.metadata.namespace)) elif namespace == i.metadata.namespace: resources.append((i.metadata.name, i.metadata.namespace)) return resources
Example #7
Source File: simple_requests_client.py From py-stellar-base with Apache License 2.0 | 6 votes |
def get(self, url: str, params: Dict[str, str] = None) -> Response: """Perform HTTP GET request. :param url: the request url :param params: the request params :return: the response from server :raise: :exc:`ConnectionError <stellar_sdk.exceptions.ConnectionError>` """ try: resp = requests.get(url=url, params=params, headers=HEADERS) except (RequestException, NewConnectionError) as err: raise ConnectionError(err) return Response( status_code=resp.status_code, text=resp.text, headers=dict(resp.headers), url=resp.url, )
Example #8
Source File: request_handler.py From Raccoon with MIT License | 5 votes |
def send(self, method="GET", *args, **kwargs): """ Send a GET/POST/HEAD request using the object's proxies and headers :param method: Method to send request in. GET/POST/HEAD """ proxies = self._get_request_proxies() try: if method.upper() in self.allowed_methods: kwargs['timeout'] = kwargs['timeout'] if 'timeout' in kwargs else 5 return request(method, proxies=proxies, headers=self.headers, cookies=self.cookies, *args, **kwargs) else: raise RequestHandlerException("Unsupported method: {}".format(method)) except ProxyError: # TODO: Apply fail over for bad proxies or drop them raise RequestHandlerException("Error connecting to proxy") except (ConnectTimeout, ReadTimeout): raise RequestHandlerException("Connection with server timed out") except NewConnectionError: raise RequestHandlerException("Address cannot be resolved") # New connection error == Can't resolve address except ConnectionError: # TODO: Increase delay raise RequestHandlerException("Error connecting to host") except TooManyRedirects: raise RequestHandlerException("Infinite redirects detected - too many redirects error") except UnicodeDecodeError: # Following issue #19, apparently some sites do not use utf-8 in their uris :<> pass
Example #9
Source File: test_client.py From gql with MIT License | 5 votes |
def test_retries_on_transport(execute_mock): """Testing retries on the transport level This forces us to override low-level APIs because the retry mechanism on the urllib3 (which uses requests) is pretty low-level itself. """ expected_retries = 3 execute_mock.side_effect = NewConnectionError( "Should be HTTPConnection", "Fake connection error" ) transport = RequestsHTTPTransport( url="http://127.0.0.1:8000/graphql", retries=expected_retries, ) client = Client(transport=transport) query = gql( """ { myFavoriteFilm: film(id:"RmlsbToz") { id title episodeId } } """ ) with client as session: # We're using the client as context manager with pytest.raises(Exception): session.execute(query) # This might look strange compared to the previous test, but making 3 retries # means you're actually doing 4 calls. assert execute_mock.call_count == expected_retries + 1
Example #10
Source File: docker_tryLogin.py From bot with GNU General Public License v3.0 | 5 votes |
def run(count=0): global bot try: bot = Bot(multi_logs=True, selenium_local_session=False, proxy_address_port=get_proxy(os.environ.get('INSTA_USER')), disable_image_load=False) selenium_url = "http://%s:%d/wd/hub" % (os.environ.get('SELENIUM', 'selenium'), 4444) bot.set_selenium_remote_session(logger=logging.getLogger(), selenium_url=selenium_url, selenium_driver=selenium_driver(selenium_url)) bot.try_first_login() except (NewConnectionError, NewConnectionError) as exc: bot.logger.warning("Exception in run: %s; try again: count=%s" % (exc, count)) if count > 3: print("Exception in run(): %s \n %s" % (exc, traceback.format_exc())) report_exception(exc) else: run(count=count + 1) except (ProtocolError, MaxRetryError) as exc: bot.logger.error("Abort because of %s; \n%s" % (exc, traceback.format_exc())) return except Exception as exc: print("Exception in run(): %s \n %s" % (exc, traceback.format_exc())) report_exception(exc) finally: print("END") bot.end()
Example #11
Source File: docker_quickstart.py From bot with GNU General Public License v3.0 | 5 votes |
def run(count=0): global bot try: bot = Bot(multi_logs=True, selenium_local_session=False, proxy_address_port=get_proxy(os.environ.get('INSTA_USER')), disable_image_load=True) selenium_url = "http://%s:%d/wd/hub" % (os.environ.get('SELENIUM', 'selenium'), 4444) bot.set_selenium_remote_session(logger=logging.getLogger(), selenium_url=selenium_url, selenium_driver=selenium_driver(selenium_url)) bot.login() bot.set_settings() bot.act() except (NewConnectionError, WebDriverException) as exc: bot.logger.warning("Exception in run: %s; try again: count=%s" % (exc, count)) if count > 3: print("Exception in run(): %s \n %s" % (exc, traceback.format_exc())) report_exception(exc) else: run(count=count + 1) except (ProtocolError, MaxRetryError) as exc: bot.logger.error("Abort because of %s; \n%s" % (exc, traceback.format_exc())) return except Exception as exc: print("Exception in run(): %s \n %s" % (exc, traceback.format_exc())) report_exception(exc) finally: print("END") bot.end()
Example #12
Source File: adapter.py From torpy with Apache License 2.0 | 5 votes |
def _new_conn(self): logger.debug('[MyHTTPSConnection] new conn %s:%i', self.host, self.port) try: self._tor_stream = self._circuit.create_stream((self.host, self.port)) logger.debug('[MyHTTPSConnection] tor_stream create_socket') return self._tor_stream.create_socket() except TimeoutError: logger.error('TimeoutError') raise ConnectTimeoutError( self, 'Connection to %s timed out. (connect timeout=%s)' % (self.host, self.timeout) ) except Exception as e: logger.error('NewConnectionError') raise NewConnectionError(self, 'Failed to establish a new connection: %s' % e)
Example #13
Source File: es_connect.py From adam_qas with GNU General Public License v3.0 | 5 votes |
def set_up_index(self): try: try: try: index_exists = self.__es_conn__.indices.exists(index=__index_name__) if not index_exists: self.create_index() else: res = self.__es_conn__.indices.get_mapping(index=__index_name__) try: current_version = res[__index_name__]['mappings']['_meta']['version'] if current_version < __index_version__: self.update_index(current_version) elif current_version is None: logger.error("Old Index Mapping. Manually reindex the index to persist your data.") print("\n -- Old Index Mapping. Manually reindex the index to persist your data.--\n") sys.exit(1) except KeyError: logger.error("Old Index Mapping. Manually reindex the index to persist your data.") print("\n -- Old Index Mapping. Manually reindex the index to persist your data.--\n") sys.exit(1) except ESConnectionError as e: logger.error("Elasticsearch is not installed or its service is not running. {0}".format(e)) print("\n -- Elasticsearch is not installed or its service is not running.--\n", e) sys.exit(1) except NewConnectionError: pass except ConnectionRefusedError: pass
Example #14
Source File: httpsession.py From AWS-Transit-Gateway-Demo-MultiAccount with MIT License | 4 votes |
def send(self, request): try: proxy_url = self._proxy_config.proxy_url_for(request.url) manager = self._get_connection_manager(request.url, proxy_url) conn = manager.connection_from_url(request.url) self._setup_ssl_cert(conn, request.url, self._verify) request_target = self._get_request_target(request.url, proxy_url) urllib_response = conn.urlopen( method=request.method, url=request_target, body=request.body, headers=request.headers, retries=False, assert_same_host=False, preload_content=False, decode_content=False, ) http_response = botocore.awsrequest.AWSResponse( request.url, urllib_response.status, urllib_response.headers, urllib_response, ) if not request.stream_output: # Cause the raw stream to be exhausted immediately. We do it # this way instead of using preload_content because # preload_content will never buffer chunked responses http_response.content return http_response except URLLib3SSLError as e: raise SSLError(endpoint_url=request.url, error=e) except (NewConnectionError, socket.gaierror) as e: raise EndpointConnectionError(endpoint_url=request.url, error=e) except ProxyError as e: raise ProxyConnectionError(proxy_url=proxy_url, error=e) except URLLib3ConnectTimeoutError as e: raise ConnectTimeoutError(endpoint_url=request.url, error=e) except URLLib3ReadTimeoutError as e: raise ReadTimeoutError(endpoint_url=request.url, error=e) except ProtocolError as e: raise ConnectionClosedError( error=e, request=request, endpoint_url=request.url ) except Exception as e: message = 'Exception received when sending urllib3 HTTP request' logger.debug(message, exc_info=True) raise HTTPClientError(error=e)
Example #15
Source File: httpsession.py From AWS-Transit-Gateway-Demo-MultiAccount with MIT License | 4 votes |
def send(self, request): try: proxy_url = self._proxy_config.proxy_url_for(request.url) manager = self._get_connection_manager(request.url, proxy_url) conn = manager.connection_from_url(request.url) self._setup_ssl_cert(conn, request.url, self._verify) request_target = self._get_request_target(request.url, proxy_url) urllib_response = conn.urlopen( method=request.method, url=request_target, body=request.body, headers=request.headers, retries=False, assert_same_host=False, preload_content=False, decode_content=False, ) http_response = botocore.awsrequest.AWSResponse( request.url, urllib_response.status, urllib_response.headers, urllib_response, ) if not request.stream_output: # Cause the raw stream to be exhausted immediately. We do it # this way instead of using preload_content because # preload_content will never buffer chunked responses http_response.content return http_response except URLLib3SSLError as e: raise SSLError(endpoint_url=request.url, error=e) except (NewConnectionError, socket.gaierror) as e: raise EndpointConnectionError(endpoint_url=request.url, error=e) except ProxyError as e: raise ProxyConnectionError(proxy_url=proxy_url, error=e) except URLLib3ConnectTimeoutError as e: raise ConnectTimeoutError(endpoint_url=request.url, error=e) except URLLib3ReadTimeoutError as e: raise ReadTimeoutError(endpoint_url=request.url, error=e) except ProtocolError as e: raise ConnectionClosedError( error=e, request=request, endpoint_url=request.url ) except Exception as e: message = 'Exception received when sending urllib3 HTTP request' logger.debug(message, exc_info=True) raise HTTPClientError(error=e)
Example #16
Source File: httpsession.py From bash-lambda-layer with MIT License | 4 votes |
def send(self, request): try: proxy_url = self._proxy_config.proxy_url_for(request.url) manager = self._get_connection_manager(request.url, proxy_url) conn = manager.connection_from_url(request.url) self._setup_ssl_cert(conn, request.url, self._verify) request_target = self._get_request_target(request.url, proxy_url) urllib_response = conn.urlopen( method=request.method, url=request_target, body=request.body, headers=request.headers, retries=False, assert_same_host=False, preload_content=False, decode_content=False, chunked=self._chunked(request.headers), ) http_response = botocore.awsrequest.AWSResponse( request.url, urllib_response.status, urllib_response.headers, urllib_response, ) if not request.stream_output: # Cause the raw stream to be exhausted immediately. We do it # this way instead of using preload_content because # preload_content will never buffer chunked responses http_response.content return http_response except URLLib3SSLError as e: raise SSLError(endpoint_url=request.url, error=e) except (NewConnectionError, socket.gaierror) as e: raise EndpointConnectionError(endpoint_url=request.url, error=e) except ProxyError as e: raise ProxyConnectionError(proxy_url=proxy_url, error=e) except URLLib3ConnectTimeoutError as e: raise ConnectTimeoutError(endpoint_url=request.url, error=e) except URLLib3ReadTimeoutError as e: raise ReadTimeoutError(endpoint_url=request.url, error=e) except ProtocolError as e: raise ConnectionClosedError( error=e, request=request, endpoint_url=request.url ) except Exception as e: message = 'Exception received when sending urllib3 HTTP request' logger.debug(message, exc_info=True) raise HTTPClientError(error=e)
Example #17
Source File: httpsession.py From deepWordBug with Apache License 2.0 | 4 votes |
def send(self, request): try: proxy_url = self._proxy_config.proxy_url_for(request.url) manager = self._get_connection_manager(request.url, proxy_url) conn = manager.connection_from_url(request.url) self._setup_ssl_cert(conn, request.url, self._verify) request_target = self._get_request_target(request.url, proxy_url) urllib_response = conn.urlopen( method=request.method, url=request_target, body=request.body, headers=request.headers, retries=False, assert_same_host=False, preload_content=False, decode_content=False, ) http_response = botocore.awsrequest.AWSResponse( request.url, urllib_response.status, urllib_response.headers, urllib_response, ) if not request.stream_output: # Cause the raw stream to be exhausted immediately. We do it # this way instead of using preload_content because # preload_content will never buffer chunked responses http_response.content return http_response except URLLib3SSLError as e: raise SSLError(endpoint_url=request.url, error=e) except (NewConnectionError, socket.gaierror) as e: raise EndpointConnectionError(endpoint_url=request.url, error=e) except ProxyError as e: raise ProxyConnectionError(proxy_url=proxy_url, error=e) except URLLib3ConnectTimeoutError as e: raise ConnectTimeoutError(endpoint_url=request.url, error=e) except URLLib3ReadTimeoutError as e: raise ReadTimeoutError(endpoint_url=request.url, error=e) except ProtocolError as e: raise ConnectionClosedError( error=e, request=request, endpoint_url=request.url ) except Exception as e: message = 'Exception received when sending urllib3 HTTP request' logger.debug(message, exc_info=True) raise HTTPClientError(error=e)
Example #18
Source File: httpsession.py From aws-builders-fair-projects with Apache License 2.0 | 4 votes |
def send(self, request): try: proxy_url = self._proxy_config.proxy_url_for(request.url) manager = self._get_connection_manager(request.url, proxy_url) conn = manager.connection_from_url(request.url) self._setup_ssl_cert(conn, request.url, self._verify) request_target = self._get_request_target(request.url, proxy_url) urllib_response = conn.urlopen( method=request.method, url=request_target, body=request.body, headers=request.headers, retries=False, assert_same_host=False, preload_content=False, decode_content=False, chunked=self._chunked(request.headers), ) http_response = botocore.awsrequest.AWSResponse( request.url, urllib_response.status, urllib_response.headers, urllib_response, ) if not request.stream_output: # Cause the raw stream to be exhausted immediately. We do it # this way instead of using preload_content because # preload_content will never buffer chunked responses http_response.content return http_response except URLLib3SSLError as e: raise SSLError(endpoint_url=request.url, error=e) except (NewConnectionError, socket.gaierror) as e: raise EndpointConnectionError(endpoint_url=request.url, error=e) except ProxyError as e: raise ProxyConnectionError(proxy_url=proxy_url, error=e) except URLLib3ConnectTimeoutError as e: raise ConnectTimeoutError(endpoint_url=request.url, error=e) except URLLib3ReadTimeoutError as e: raise ReadTimeoutError(endpoint_url=request.url, error=e) except ProtocolError as e: raise ConnectionClosedError( error=e, request=request, endpoint_url=request.url ) except Exception as e: message = 'Exception received when sending urllib3 HTTP request' logger.debug(message, exc_info=True) raise HTTPClientError(error=e)