Python requests.exceptions 模块,InvalidSchema() 实例源码

我们从Python开源项目中,提取了以下5个代码示例,用于说明如何使用requests.exceptions.InvalidSchema()

项目:metatab    作者:Metatab    | 项目源码 | 文件源码
def find_decl_doc(self, name):


        raise IncludeError(name)

        import requests
        from requests.exceptions import InvalidSchema
        url = METATAB_ASSETS_URL + name + '.csv'
        try:
            # See if it exists online in the official repo
            r = requests.head(url, allow_redirects=False)
            if r.status_code == requests.codes.ok:
                return url

        except InvalidSchema:
            pass  # It's probably FTP
项目:dpm-py    作者:oki-archive    | 项目源码 | 文件源码
def test_connerror_invalid_url_schema(self):
        # GIVEN server url with invalid 'htt:' schema
        self.config['server'] = 'htt://127.0.0.1'

        # WHEN dpm publish is invoked
        try:
            result = self.invoke(cli, ['publish', ])
        except Exception as e:
            result = e

        # THEN InvalidSchema should be raised
        assert isinstance(result, InvalidSchema)
        # AND it should say that schema is invalid
        assert "No connection adapters were found for 'htt://127.0.0.1/api/auth/token'" in str(result)
项目:python-steamcommunity    作者:DrBomb    | 项目源码 | 文件源码
def raiseLostAuth(f):
    @wraps(f)
    def lost_auth_wrapper(*args,**kwargs):
        try:
            f(args,**kwargs)
        except InvalidSchema as e:
            if re.search(r'steammobile://lostauth',e.message) is not None:
                raise SteamExceptions.LostAuthException("Login was lost, relog again")
    return lost_auth_wrapper
项目:reddit2telegram    作者:Fillll    | 项目源码 | 文件源码
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()
项目:elasticsearch-synonyms    作者:prashnts    | 项目源码 | 文件源码
def load_synonyms(path):
  try:
    r = requests.get(path)
    content = r.text
  except (MissingSchema, InvalidSchema, InvalidURL):
    try:
      with open(path, encoding='utf-8') as fp:
        content = fp.read()
    except (OSError, IOError):
      raise TypeError('Invalid Path: "{0}". Ensure it is either a URL or Correct FS Path.'.format(path))

  return SynParser.get_mapping(content)