How to use the simplejson.errors.JSONDecodeError function in simplejson

To help you get started, we’ve selected a few simplejson examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github simplejson / simplejson / simplejson / _pypy_speedups.py View on Github external
except IndexError:
            raise JSONDecodeError("Expecting property name", s, len(s))
        end += 1
        while 1:
            key, end = scanstring(s, end, encoding, strict)
            key = memo.setdefault(key, key)
            try:
                # To skip some function call overhead we optimize the fast
                # paths where the JSON key separator is ": " or just ":".
                if s[end] != ':':
                    while is_whitespace(s[end]):
                        end += 1
                    if s[end] != ':':
                        raise JSONDecodeError("Expecting : delimiter", s, end)
            except IndexError:
                raise JSONDecodeError("Expecting : delimiter", s, len(s))
            end += 1
            try:
                while is_whitespace(s[end]):
                    end += 1
            except IndexError:
                pass
            try:
                value, end = _scan_once(s, end)
            except StopIteration:
                raise JSONDecodeError("Expecting object", s, end)
            setitem(pairs, key, value)
            try:
                while is_whitespace(s[end]):
                    end += 1
                nextchar = s[end]
                end += 1
github aetros / aetros-cli / aetros / api.py View on Github external
def parse_json(content):
    try:
        a = simplejson.loads(content)
    except simplejson.errors.JSONDecodeError as e:
        raise ApiError("Could not decode response from server: %s, response: %s\n" % (str(e), content))

    if isinstance(a, dict) and 'error' in a:
        raise ApiError('API request failed %s: %s.' % (a['error'], a['message']), a['error'])

    return a
github simplejson / simplejson / simplejson / _pypy_speedups.py View on Github external
except IndexError:
                pass
            try:
                value, end = _scan_once(s, end)
            except StopIteration:
                raise JSONDecodeError("Expecting object", s, end)
            setitem(pairs, key, value)
            try:
                while is_whitespace(s[end]):
                    end += 1
                nextchar = s[end]
                end += 1
                if nextchar == '}':
                    break
                elif nextchar != ',':
                    raise JSONDecodeError("Expecting , delimiter", s, end - 1)
                while is_whitespace(s[end]):
                    end += 1
                if s[end] != '"':
                    raise JSONDecodeError("Expecting property name", s, end)
                end += 1
            except IndexError:
                raise JSONDecodeError("Expecting property name", s, len(s))
        return finalize(pairs), end
    return parse_object
github Pirionfr / pyLinky / pylinky / client.py View on Github external
if p_p_resource_id == 'urlCdcHeure':
                raw_res = self._api.get_consumption_load_curve(upids, start_date, end_date)
            else:
                raw_res = self._api.get_daily_consumption(upids, start_date, end_date)
        except OSError as e:
            raise PyLinkyAccessException("Could not access enedis.fr: " + str(e))

        if 404 == raw_res.status_code:
            raise PyLinkyException("No data")

        if 500 == raw_res.status_code:
            raise PyLinkyMaintenanceException("Site in maintenance")

        try:
            json_output = raw_res.json()
        except (OSError, json.decoder.JSONDecodeError, simplejson.errors.JSONDecodeError) as e:
            raise PyLinkyException("Impossible to decode response: " + str(e) + "\nResponse was: " + str(raw_res.text))

        if json_output.get('error'):
            description = json_output.get('error_description')
            description = json_output['error'] if description is None else description
            raise PyLinkyEnedisException("Enedis.fr answered with an error: " + description)

        return json_output['meter_reading']
github zbarge / stocklook / stocklook / crypto / etherium.py View on Github external
{'previous_url': 'https://api.blockcypher.com/v1/eth/main/blocks/004cc9d90eea8c9a8a55a58a7bdea9bd57bdf25daffb24c8302ac50a452e5743',
    'low_gas_price': 5000000000,
    'peer_count': 144,
    'high_gas_price': 21320232122,
    'latest_url': 'https://api.blockcypher.com/v1/eth/main/blocks/2c6e2e3ea3a59147fdbdaab2400a511955b89fb451611fa7af659804ab4da127',
    'unconfirmed_count': 4234, 'name': 'ETH.main', 'height': 4825457,
    'last_fork_hash': '5a78fdcd8376fdd01d514fbec113de641b1b9d993bdf660e91965e201f9b7fe5',
    'hash': '2c6e2e3ea3a59147fdbdaab2400a511955b89fb451611fa7af659804ab4da127',
    'time': '2017-12-30T18:40:02.147746029Z',
    'previous_hash': '004cc9d90eea8c9a8a55a58a7bdea9bd57bdf25daffb24c8302ac50a452e5743',
    'last_fork_height': 4825453,
    'medium_gas_price': 20000000000}
    """
    try:
        return requests.get(ETH_CHAIN_STATS_URL).json()
    except (requests.exceptions.ConnectionError, JSONDecodeError):
        sleep(1)
        return eth_get_chain_stats()
github theLSA / ueditor-getshell / ueGetshell.py View on Github external
else:
						errorState = rst.json()["list"][0]['state']
				
						#print 'Getshell failed! Error: ' + errorState
						lock.acquire()
						f4fail.write(fullUrl+': '+errorState+'\n')
						lock.release()
				else:
				
					errorState = rst.json()['state']
				
					#print 'Getshell failed! Error: ' + errorState
					lock.acquire()
					f4fail.write(fullUrl+': '+errorState+'\n')
					lock.release()
			except simplejson.errors.JSONDecodeError:
				#print 'Getshell failed! Error: JSONDecodeError'
				lock.acquire()
				f4fail.write(fullUrl+': '+'Getshell failed! Error: JSONDecodeError'+'\n')
				lock.release()
				continue
			except:
				#print 'Getshell failed! Error: Unkonwn error'
				lock.acquire()
				f4fail.write(fullUrl+': '+'Getshell failed! Error: Unknown error'+'\n')
				lock.release()	
				continue			


		else:
			#print 'Getshell failed! status code: ' + str(rst.status_code)
			lock.acquire()
github simplejson / simplejson / simplejson / _pypy_speedups.py View on Github external
# Find the next "terminator"
        chunk_end = end
        needs_decode = False
        try:
            while 1:
                c = s[chunk_end]
                if (c == '"') or (c == '\\'):
                    break
                ordc = ord(c)
                if (ordc <= 0x1f):
                    break
                elif (not is_unicode) and (ordc > 0x7f):
                    needs_decode = True
                chunk_end += 1
        except IndexError:
            raise JSONDecodeError(
                "Unterminated string starting at", s, begin)
        else:
            if end == chunk_end:
                content = empty_str
            else:
                content = s[end:chunk_end]
            terminator = c
            end = chunk_end + 1
        # Content is contains zero or more unescaped string characters
        if not is_unicode and needs_decode:
            content = unicode(content, encoding)
        # Terminator is the end of string, a literal control character,
        # or a backslash denoting that an escape sequence follows
        if terminator == '"':
            if chunks is None:
                return content, end
github simplejson / simplejson / simplejson / _pypy_speedups.py View on Github external
except StopIteration:
                raise JSONDecodeError("Expecting object", s, end)
            setitem(pairs, key, value)
            try:
                while is_whitespace(s[end]):
                    end += 1
                nextchar = s[end]
                end += 1
                if nextchar == '}':
                    break
                elif nextchar != ',':
                    raise JSONDecodeError("Expecting , delimiter", s, end - 1)
                while is_whitespace(s[end]):
                    end += 1
                if s[end] != '"':
                    raise JSONDecodeError("Expecting property name", s, end)
                end += 1
            except IndexError:
                raise JSONDecodeError("Expecting property name", s, len(s))
        return finalize(pairs), end
    return parse_object
github simplejson / simplejson / simplejson / _pypy_speedups.py View on Github external
def parse_object((s, end), _scan_once):
        pairs = new_obj()
        try:
            while is_whitespace(s[end]):
                end += 1
            nextchar = s[end]
            if nextchar == '}':
                return finalize(pairs), end + 1
            elif nextchar != '"':
                JSONDecodeError("Expecting property name", s, end)
        except IndexError:
            raise JSONDecodeError("Expecting property name", s, len(s))
        end += 1
        while 1:
            key, end = scanstring(s, end, encoding, strict)
            key = memo.setdefault(key, key)
            try:
                # To skip some function call overhead we optimize the fast
                # paths where the JSON key separator is ": " or just ":".
                if s[end] != ':':
                    while is_whitespace(s[end]):
                        end += 1
                    if s[end] != ':':
                        raise JSONDecodeError("Expecting : delimiter", s, end)
            except IndexError:
                raise JSONDecodeError("Expecting : delimiter", s, len(s))
            end += 1
            try:
github ShopRunner / apparate / apparate / update_databricks_library.py View on Github external
def __init__(self, response):
        Exception.__init__(self, response)
        try:
            res_body = response.json()
        except JSONDecodeError:
            self.code = 'http {}'.format(response.status_code)
            # non-json error message, didn't bother parsing neatly
            self.message = response.text
        else:
            if 'error_code' in res_body.keys():
                self.code = res_body['error_code']
                self.message = res_body['message']
            else:
                self.code = 'http {}'.format(response.status_code)
                self.message = res_body['error']