Python requests.exceptions.InvalidSchema() Examples
The following are 10
code examples of requests.exceptions.InvalidSchema().
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
requests.exceptions
, or try the search function
.
Example #1
Source File: connector.py From indico-plugins with MIT License | 6 votes |
def _validate_server_url(self): """Validates self.server_url""" try: request = requests.head(self.server_url) if request.status_code >= 400: raise InvenioConnectorServerError( "Unexpected status code '%d' accessing URL: %s" % (request.status_code, self.server_url)) except (InvalidSchema, MissingSchema) as err: raise InvenioConnectorServerError( "Bad schema, expecting http:// or https://:\n %s" % (err,)) except ConnectionError as err: raise InvenioConnectorServerError( "Couldn't establish connection to '%s':\n %s" % (self.server_url, err)) except InvalidURL as err: raise InvenioConnectorServerError( "Invalid URL '%s':\n %s" % (self.server_url, err)) except RequestException as err: raise InvenioConnectorServerError( "Unknown error connecting to '%s':\n %s" % (self.server_url, err))
Example #2
Source File: __init__.py From reddit2telegram with MIT License | 6 votes |
def md5_sum_from_url(url): try: r = requests.get(url, stream=True) except InvalidSchema: return None except MissingSchema: return None chunk_counter = 0 hash_store = hashlib.md5() for chunk in r.iter_content(chunk_size=1024): if chunk: # filter out keep-alive new chunks hash_store.update(chunk) chunk_counter += 1 # It is not possible to send greater than 50 MB via Telegram if chunk_counter > 50 * 1024: return None return hash_store.hexdigest()
Example #3
Source File: helpers.py From Varken with MIT License | 5 votes |
def connection_handler(session, request, verify, as_is_reply=False): air = as_is_reply s = session r = request v = verify return_json = False disable_warnings(InsecureRequestWarning) try: get = s.send(r, verify=v) if get.status_code == 401: if 'NoSiteContext' in str(get.content): logger.info('Your Site is incorrect for %s', r.url) elif 'LoginRequired' in str(get.content): logger.info('Your login credentials are incorrect for %s', r.url) else: logger.info('Your api key is incorrect for %s', r.url) elif get.status_code == 404: logger.info('This url doesnt even resolve: %s', r.url) elif get.status_code == 200: try: return_json = get.json() except JSONDecodeError: logger.error('No JSON response. Response is: %s', get.text) if air: return get except InvalidSchema: logger.error("You added http(s):// in the config file. Don't do that.") except SSLError as e: logger.error('Either your host is unreachable or you have an SSL issue. : %s', e) except ConnectionError as e: logger.error('Cannot resolve the url/ip/port. Check connectivity. Error: %s', e) except ChunkedEncodingError as e: logger.error('Broken connection during request... oops? Error: %s', e) return return_json
Example #4
Source File: UserPassOrTokenClient.py From matrixcli with GNU General Public License v3.0 | 5 votes |
def example(host, user, password, token): """run the example.""" client = None try: if token: print('token login') client = MatrixClient(host, token=token, user_id=user) else: print('password login') client = MatrixClient(host) token = client.login_with_password(user, password) print('got token: %s' % token) except MatrixRequestError as e: print(e) if e.code == 403: print("Bad username or password") exit(2) elif e.code == 401: print("Bad username or token") exit(3) else: print("Verify server details.") exit(4) except MissingSchema as e: print(e) print("Bad formatting of URL.") exit(5) except InvalidSchema as e: print(e) print("Invalid URL schema") exit(6) print("is in rooms") for room_id, room in client.get_rooms().items(): print(room_id)
Example #5
Source File: test_http_checks.py From syntribos with Apache License 2.0 | 5 votes |
def test_invalid_schema(self): signal = http_checks.check_fail(rex.InvalidSchema()) self._assert_has_tags(self.bad_request_tags, signal) self._assert_has_slug("HTTP_FAIL_INVALID_SCHEMA", signal)
Example #6
Source File: __init__.py From opentelemetry-python with Apache License 2.0 | 5 votes |
def _exception_to_canonical_code(exc: Exception) -> StatusCanonicalCode: if isinstance( exc, (InvalidURL, InvalidSchema, MissingSchema, URLRequired, ValueError), ): return StatusCanonicalCode.INVALID_ARGUMENT if isinstance(exc, Timeout): return StatusCanonicalCode.DEADLINE_EXCEEDED return StatusCanonicalCode.UNKNOWN
Example #7
Source File: UserPassOrTokenClient.py From matrix-python-sdk with Apache License 2.0 | 5 votes |
def example(host, user, password, token): """run the example.""" client = None try: if token: print('token login') client = MatrixClient(host, token=token) else: print('password login') client = MatrixClient(host) token = client.login(user, password) print('got token: %s' % token) except MatrixRequestError as e: print(e) if e.code == 403: print("Bad username or password") exit(2) elif e.code == 401: print("Bad username or token") exit(3) else: print("Verify server details.") exit(4) except MissingSchema as e: print(e) print("Bad formatting of URL.") exit(5) except InvalidSchema as e: print(e) print("Invalid URL schema") exit(6) print("is in rooms") for room_id, room in client.get_rooms().items(): print(room_id)
Example #8
Source File: subset_base.py From flyingpigeon with Apache License 2.0 | 5 votes |
def is_opendap_url(url): """ Check if a provided url is an OpenDAP url. The DAP Standard specifies that a specific tag must be included in the Content-Description header of every request. This tag is one of: "dods-dds" | "dods-das" | "dods-data" | "dods-error" So we can check if the header starts with `dods`. Even then, some OpenDAP servers seem to not include the specified header... So we need to let the netCDF4 library actually open the file. """ from requests.exceptions import MissingSchema, InvalidSchema from requests.exceptions import ConnectionError as reqCE try: content_description = requests.head(url, timeout=5).headers.get("Content-Description") except (ConnectionError, reqCE, MissingSchema, InvalidSchema): return False if content_description: return content_description.lower().startswith("dods") else: try: dataset = nc.Dataset(url) except OSError: return False return dataset.disk_format in ('DAP2', 'DAP4')
Example #9
Source File: verify.py From lemur with Apache License 2.0 | 4 votes |
def crl_verify(cert, cert_path): """ Attempts to verify a certificate using CRL. :param cert: :param cert_path: :return: True if certificate is valid, False otherwise :raise Exception: If certificate does not have CRL """ try: distribution_points = cert.extensions.get_extension_for_oid( x509.OID_CRL_DISTRIBUTION_POINTS ).value except x509.ExtensionNotFound: current_app.logger.debug( "No CRLDP extension in certificate {}".format(cert.serial_number) ) return None for p in distribution_points: point = p.full_name[0].value if point not in crl_cache: current_app.logger.debug("Retrieving CRL: {}".format(point)) try: response = requests.get(point) if response.status_code != 200: raise Exception("Unable to retrieve CRL: {0}".format(point)) except InvalidSchema: # Unhandled URI scheme (like ldap://); skip this distribution point. continue except ConnectionError: raise Exception("Unable to retrieve CRL: {0}".format(point)) crl_cache[point] = x509.load_der_x509_crl( response.content, backend=default_backend() ) else: current_app.logger.debug("CRL point is cached {}".format(point)) for r in crl_cache[point]: if cert.serial_number == r.serial_number: try: reason = r.extensions.get_extension_for_class(x509.CRLReason).value # Handle "removeFromCRL" revoke reason as unrevoked; # continue with the next distribution point. # Per RFC 5280 section 6.3.3 (k): # https://tools.ietf.org/html/rfc5280#section-6.3.3 if reason == x509.ReasonFlags.remove_from_crl: break except x509.ExtensionNotFound: pass current_app.logger.debug( "CRL reports certificate " "revoked: {}".format(cert.serial_number) ) return False return True
Example #10
Source File: http.py From syntribos with Apache License 2.0 | 4 votes |
def check_fail(exception): """Checks for a requestslib exception, returns a signal if found. If this Exception is an instance of :class:`requests.exceptions.RequestException`, determine what kind of exception was raised. If not, return the results of from_generic_exception. :param Exception exception: An Exception object :returns: Signal with exception details :rtype: :class:`syntribos.signal.SynSignal` """ check_name = "HTTP_CHECK_FAIL" def uncamel(string): string = re.sub("(.)([A-Z][a-z]+)", r"\1_\2", string) return re.sub("([a-z0-9])([A-Z])", r"\1_\2", string).upper() if not isinstance(exception, rex.RequestException): return syntribos.signal.from_generic_exception(exception) data = { "response": exception.response, "request": exception.request, "exception": exception, "exception_name": uncamel(exception.__class__.__name__) } text = "An exception was encountered when sending the request. {desc}" slug = "HTTP_FAIL_{exc}".format(exc=data["exception_name"]) tags = set(["EXCEPTION_RAISED"]) invalid_request_exceptions = (rex.URLRequired, rex.MissingSchema, rex.InvalidSchema, rex.InvalidURL) if exception.__doc__: text = text.format(desc=exception.__doc__) else: text = text.format( desc="An unknown exception was raised. Please report this.") # CONNECTION FAILURES if isinstance(exception, (rex.ProxyError, rex.SSLError, rex.ChunkedEncodingError, rex.ConnectionError)): tags.update(["CONNECTION_FAIL"]) # TIMEOUTS elif isinstance(exception, (rex.ConnectTimeout, rex.ReadTimeout)): tags.update(["CONNECTION_TIMEOUT", "SERVER_FAIL"]) # INVALID REQUESTS elif isinstance(exception, invalid_request_exceptions): tags.update(["INVALID_REQUEST", "CLIENT_FAIL"]) return syntribos.signal.SynSignal( text=text, slug=slug, strength=1.0, tags=list(tags), data=data, check_name=check_name)