python类MissingSchema()的实例源码

qiubaiadult.py 文件源码 项目:Python 作者: Guzi219 项目源码 文件源码 阅读 34 收藏 0 点赞 0 评论 0
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:??
test_publish_connerror.py 文件源码 项目:dpm-py 作者: oki-archive 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
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)
requests_tests.py 文件源码 项目:apm-agent-python 作者: elastic 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
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)
requests_tests.py 文件源码 项目:apm-agent-python 作者: elastic 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
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('')
gbf.py 文件源码 项目:dogbot 作者: moondropx 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
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
monitor_manager.py 文件源码 项目:infrastructure-monitor 作者: mypebble 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
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)
test_monitor_site.py 文件源码 项目:infrastructure-monitor 作者: mypebble 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
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)
utils.py 文件源码 项目:reddit2telegram 作者: Fillll 项目源码 文件源码 阅读 20 收藏 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()
test_integ_Validator.py 文件源码 项目:son-cli 作者: sonata-nfv 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
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")
github.py 文件源码 项目:gitsome 作者: donnemartin 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
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
helper.py 文件源码 项目:es-tenso 作者: AliceAndTheBuilders 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
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
utils.py 文件源码 项目:elasticsearch-synonyms 作者: prashnts 项目源码 文件源码 阅读 19 收藏 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)
test_rest.py 文件源码 项目:homeassistant 作者: NAStools 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
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)


问题


面经


文章

微信
公众号

扫码关注公众号