当前位置: 首页>>代码示例>>Python>>正文


Python scanner.JSONDecodeError方法代码示例

本文整理汇总了Python中simplejson.scanner.JSONDecodeError方法的典型用法代码示例。如果您正苦于以下问题:Python scanner.JSONDecodeError方法的具体用法?Python scanner.JSONDecodeError怎么用?Python scanner.JSONDecodeError使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在simplejson.scanner的用法示例。


在下文中一共展示了scanner.JSONDecodeError方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get_aggregate_swagger

# 需要导入模块: from simplejson import scanner [as 别名]
# 或者: from simplejson.scanner import JSONDecodeError [as 别名]
def get_aggregate_swagger(self):
        """Get swagger files associated with the aggregates.

        Returns:
            A dict of swagger spec.
        """
        if 'apis' in self.yaml_file:  # Check if apis is in the config file
            for api_name, api_url in self.yaml_file['apis'].items():
                if api_name not in self.swagger_apis:
                    # Get the swagger.json
                    try:
                        self.swagger_apis[api_name] = {'spec': self.get_swagger_from_url(api_url),
                                                       'url': self.parse_value(api_url)}
                        self.errors.remove(api_url)
                    except (JSONDecodeError, RequestException) as exc:
                        if api_url not in self.errors:
                            self.errors.append(api_url)
                        logger.warning(u'Cannot get swagger from {0}: {1}'.format(api_url, repr(exc)))
                    except ValueError:
                        logger.info(u'Cannot remove {0} from errors'.format(api_url))
        return self.swagger_apis 
开发者ID:Trax-air,项目名称:swagger-aggregator,代码行数:23,代码来源:swagger_aggregator.py

示例2: _read_cache_from_file

# 需要导入模块: from simplejson import scanner [as 别名]
# 或者: from simplejson.scanner import JSONDecodeError [as 别名]
def _read_cache_from_file(self):
        """Read the contents of the cache from a file on disk."""
        cache = {}
        try:
            with(open(self._cache_file_name, 'r')) as fp:
                contents = fp.read()
                cache = simplejson.loads(contents)
        except (IOError, JSONDecodeError):
            # The file could not be read. This is not a problem if the file does not exist.
            pass

        return cache 
开发者ID:Yelp,项目名称:threat_intel,代码行数:14,代码来源:api_cache.py

示例3: __auth_request

# 需要导入模块: from simplejson import scanner [as 别名]
# 或者: from simplejson.scanner import JSONDecodeError [as 别名]
def __auth_request(
        self, method, url, payload=None, url_params=None, json_response=True
    ):
        params = [("token", self.token)]
        if url_params:
            params += url_params
        logger.debug(
            "{method} {url} - Params: {params}- Payload: {payload}".format(
                method=method, url=url, params=params, payload=payload
            )
        )
        r = requests.request(
            method=method,
            url=url,
            params=params,
            json=payload,
            verify=self.verify,
            allow_redirects=True,
        )
        if not r.ok:
            logger.error(r.content)
        r.raise_for_status()
        if json_response:
            try:
                return r.json()
            except JSONDecodeError:
                logger.error("Could not decode JSON response")
                return r
        else:
            return r 
开发者ID:pschmitt,项目名称:guacapy,代码行数:32,代码来源:client.py

示例4: fetch

# 需要导入模块: from simplejson import scanner [as 别名]
# 或者: from simplejson.scanner import JSONDecodeError [as 别名]
def fetch(url):
    s = requests.Session()
    s.headers.update({'user-agent': get_user_agent()})
    proxies = {
        'http': Proxy.get_random()['address'],
    }
    html_text = s.get(url, timeout=TIMEOUT, proxies=proxies).text
    js_url = gen_js_url(url)
    try:
        js_data = s.get(js_url, timeout=TIMEOUT, proxies=proxies).json()
    except JSONDecodeError:
        raise RequestException()
    return html_text, js_data 
开发者ID:dongweiming,项目名称:web_develop,代码行数:15,代码来源:save_article_content.py

示例5: test_get_bad_json

# 需要导入模块: from simplejson import scanner [as 别名]
# 或者: from simplejson.scanner import JSONDecodeError [as 别名]
def test_get_bad_json(self, resp_mock):
        """Test treadmill.restclient.get bad JSON"""
        resp_mock.return_value.status_code = http_client.INTERNAL_SERVER_ERROR
        resp_mock.return_value.text = '{"bad json"'
        resp_mock.return_value.json.side_effect = sjs.JSONDecodeError(
            'Foo', '{"bad json"', 1
        )

        self.assertRaises(
            restclient.MaxRequestRetriesError,
            restclient.get, 'http://foo.com', '/', retries=1) 
开发者ID:Morgan-Stanley,项目名称:treadmill,代码行数:13,代码来源:restclient_test.py

示例6: _update_status

# 需要导入模块: from simplejson import scanner [as 别名]
# 或者: from simplejson.scanner import JSONDecodeError [as 别名]
def _update_status(repo, commit, token, data):
    "Sends the status update's data using the GitHub API."

    header = {'Authorization': 'token ' + token}
    api_url = ("https://api.github.com/repos/%s/statuses/%s" %
               (repo, commit))

    if __name__ == '__main__':
        eprint("Updating status of commit", commit, "with data", data)

    try:
        # use data= instead of json= in case we're running on an older requests
        resp = requests.post(api_url, data=json.dumps(data), headers=header)
        _print_ratelimit_info(resp)
        body = resp.json()
    except JSONDecodeError:
        eprint("Expected JSON, but received:")
        eprint("---")
        eprint(resp.content)
        eprint("---")
        eprint("Retrying...")
        resp = requests.post(api_url, data=json.dumps(data), headers=header)
        body = resp.json()

    # pylint: disable=no-member
    if resp.status_code != requests.codes.created:
        if (resp.status_code == requests.codes.unprocessable
                and body is not None and 'message' in body
                and "No commit found for SHA" in body['message']):
            raise CommitNotFoundException()

        # Some other error happened.
        errmsg = "Failed to update commit status [HTTP %d]" % resp.status_code
        errmsg += "\n" + str(resp.headers)
        if body is not None:
            errmsg += "\n" + str(body)
        raise Exception(errmsg)


# XXX: add CLI support and deduplicate with status() 
开发者ID:projectatomic,项目名称:papr,代码行数:42,代码来源:gh.py

示例7: generate_operation_id_function

# 需要导入模块: from simplejson import scanner [as 别名]
# 或者: from simplejson.scanner import JSONDecodeError [as 别名]
def generate_operation_id_function(self, spec, uri, path, action, func_name):
        """Generate a function to handle the current path.

        Args:
            spec: spec of the action the generated function should handle.
            uri: uri of the microservice corresponding to the spec.
            func_name: name the generated function should have.

        Returns:
            A function with func_name as name.
        """
        @retry_http
        def func(*args, **kwargs):
            """Handle a flask request for the current action.

            """
            # Get url from spec and flask query
            url = u'{0}{1}?{2}'.format(uri[func.__name__], path[func.__name__], flask.request.query_string)
            p = re.compile('{(.+)}')
            for path_param in re.findall(p, url):
                for k, v in kwargs.items():
                    if k == path_param:
                        url = url.replace('{{{0}}}'.format(k), str(v))

            requests_meth = getattr(requests, action[func.__name__])

            headers = {k: v for k, v in dict(flask.request.headers).items() if v}

            if not flask.request.headers.get('Content-Type', '').startswith('multipart/form-data'):
                req = requests_meth(url, data=flask.request.data, headers=headers)
            else:
                # Remove Content-Length because it cause error on nginx side
                if 'Content-Length' in headers:
                    headers['X-Content-Length'] = headers['Content-Length']
                    del headers['Content-Length']

                req = requests_meth(url, data=flask.request.stream, headers=headers)

            try:
                return (self.filter_definition(req.json()), req.status_code)
            except JSONDecodeError:
                return (req.text, req.status_code)
        func.__name__ = func_name
        return func 
开发者ID:Trax-air,项目名称:swagger-aggregator,代码行数:46,代码来源:swagger_aggregator.py


注:本文中的simplejson.scanner.JSONDecodeError方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。