python类InvalidSchema()的实例源码

resolver.py 文件源码 项目:metatab 作者: Metatab 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
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
test_publish_connerror.py 文件源码 项目:dpm-py 作者: oki-archive 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
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)
utils.py 文件源码 项目:python-steamcommunity 作者: DrBomb 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
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
utils.py 文件源码 项目:reddit2telegram 作者: Fillll 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
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()
utils.py 文件源码 项目:elasticsearch-synonyms 作者: prashnts 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
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)


问题


面经


文章

微信
公众号

扫码关注公众号