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

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

项目:Python    作者:Guzi219    | 项目源码 | 文件源码
def saveFile(self, url, page, idx):
        user_define_name = self.now_date() + '_p_' + str(page) + '_' + string.zfill(idx, 2)  # ??2?
        file_ext = self.file_extension(url)  # ???
        save_file_name = user_define_name + "_" + file_ext

        # ???????open??
        # urllib.urlretrieve(item[0], self.save_path + save_file_name)
        # ????
        url = self.CheckUrlValidate(url)
        try:
            pic = requests.get(url, timeout=10)
            f = open(self.store_dir + os.sep + save_file_name, 'wb')
            f.write(pic.content)
            f.close()
            print '\ndone save file ' + save_file_name
        except ReadTimeout:
              print 'save file %s failed. cause by timeout(10)' %(save_file_name)
        except MissingSchema:
            print 'invalid url %s' %(url)
        except Exception, e:
            print e


    #??url????http:??
项目:dpm-py    作者:oki-archive    | 项目源码 | 文件源码
def test_connerror_missing_url_schema(self):
        # GIVEN server url with missing schema
        self.config['server'] = '127.0.0.1'

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

        # THEN MissingSchema should be raised
        assert isinstance(result, MissingSchema)
        # AND it should say that schema is invalid
        assert "Invalid URL '127.0.0.1/api/auth/token': No schema supplied. Perhaps you meant http://127.0.0.1/api/auth/token?" in str(result)
项目:apm-agent-python    作者:elastic    | 项目源码 | 文件源码
def test_requests_instrumentation_malformed_none(elasticapm_client):
    elasticapm_client.begin_transaction("transaction.test")
    with capture_span("test_request", "test"):
        with pytest.raises(MissingSchema):
            requests.get(None)
项目:apm-agent-python    作者:elastic    | 项目源码 | 文件源码
def test_requests_instrumentation_malformed_schema(elasticapm_client):
    elasticapm_client.begin_transaction("transaction.test")
    with capture_span("test_request", "test"):
        with pytest.raises(MissingSchema):
            requests.get('')
项目:dogbot    作者:moondropx    | 项目源码 | 文件源码
def gbf(bot, message):
    result = GBF_PATTERN.findall(message.text)
    for index, match in enumerate(result):
        if index > 10:
            return False
        url = match[0]
        if url.split('.')[-1] in ['png', 'jpg', 'jpeg', 'gif']:
            return False
        if url not in match_urls:
            try:
                resp = requests.get(url)
            except MissingSchema:
                resp = requests.get('http://' + url)
            if 'granblue' in resp.url:
                match_urls.append(url)
                reply(bot, message, '?????????')
                return True
        else:
            reply(bot, message, '?????????')
            return True
项目:infrastructure-monitor    作者:mypebble    | 项目源码 | 文件源码
def check_sites(self):
        errors = []

        try:
            errors = [site.create_slack_message() for site in self.sites
                      if not site.check_status_code()]
        except (ConnectionError, MissingSchema, Timeout) as e:
            self.slack.post_message(unicode(e.message))
            self.logger.error(unicode(e.message))

        for error in errors:
            self.slack.post_message(error)
            self.logger.error(error)

        return len(errors)
项目:infrastructure-monitor    作者:mypebble    | 项目源码 | 文件源码
def test_get_status_code_with_bad_url(self):
        # No prefix or suffixes
        bad_url = "url"
        expected_status_code = 200

        monitor = MonitorSite(url=bad_url,
                              expected_status_code=expected_status_code)

        self.assertRaises(MissingSchema, monitor.get_status_code)

        bad_url = "url.com"
        expected_status_code = 200

        monitor = MonitorSite(url=bad_url,
                              expected_status_code=expected_status_code)

        self.assertRaises(MissingSchema, monitor.get_status_code)
项目: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()
项目:son-cli    作者:sonata-nfv    | 项目源码 | 文件源码
def test_load_invalid_remote_template_invalid(self):
        """
        Test if it raises an error with an invalid
        schema URL.
        """
        self.assertRaises(MissingSchema,
                          load_remote_schema,
                          "some.incorrect/..url")
项目:gitsome    作者:donnemartin    | 项目源码 | 文件源码
def authenticate(func):
        """Decorator that authenticates credentials.

        :type func: callable
        :param func: A method to execute if authorization passes.

        :return: The return value of `func` if authorization passes, or
            None if authorization fails.
        """
        def auth_wrapper(self, *args, **kwargs):
            self.config.authenticate()
            self.config.save_config()
            if self.config.check_auth():
                try:
                    return func(self, *args, **kwargs)
                except SSLError:
                    click.secho(('SSL cert verification failed.\n  Try running '
                                 'gh configure --enterprise\n  and type '
                                 "'n' when asked whether to verify SSL certs."),
                                fg=self.config.clr_error)
                except MissingSchema:
                    click.secho('Invalid GitHub Enterprise url',
                                fg=self.config.clr_error)
                except AuthenticationFailed:
                    self.config.print_auth_error()
        return auth_wrapper
项目:es-tenso    作者:AliceAndTheBuilders    | 项目源码 | 文件源码
def is_uri_reachable(uri: str) -> bool:
        try:
            return requests.head(uri).status_code == requests.codes.ok
        except MissingSchema:
            return False

    ##
    # Identifies the kind of the source and initializes it
    #
    # @param args   The arguments passed to the application
项目: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)
项目:homeassistant    作者:NAStools    | 项目源码 | 文件源码
def test_setup_missing_schema(self):
        """Test setup with resource missing schema."""
        with self.assertRaises(MissingSchema):
            rest.setup_platform(self.hass, {
                'platform': 'rest',
                'resource': 'localhost',
                'method': 'GET'
            }, None)