The error arises because the “data” is of type bytes so you have to decode it into a string before using json.loads
to turn it into a json object. So to solve the problem:
uh = urllib.request.urlopen(url) data = uh.read() print ('Retrieved',len(data),'characters') js = json.loads(data.decode("utf-8"))
Also, str(data) in the code you share will work in Python 2.x but not in Python 3.x because str() doesn’t turn bytes into a string in 3.x.
Related Posts:
- Python error load JSON code of google API
- Why am I seeing “TypeError: string indices must be integers”?
- How to prettyprint a JSON file?
- pandas read_json: “If using all scalar values, you must pass an index”
- JSONDecodeError: Expecting value: line 1 column 1 (char 0)
- Converting dictionary to JSON
- JSONDecodeError: Expecting value: line 1 column 1 (char 0)
- JSONDecodeError: Expecting value: line 1 column 1 (char 0)
- How to parse data in JSON format?
- json.dumps vs flask.jsonify
- TypeError: unhashable type: ‘dict’, when dict used as a key for another dict
- is not JSON serializable
- How to make a class JSON serializable
- Convert a python dict to a string and back
- TypeError: Object of type ‘bytes’ is not JSON serializable
- Python ValueError: No JSON object could be decoded
- How to POST JSON data with Python Requests?
- Return JSON response from Flask view
- How to overcome “datetime.datetime not JSON serializable”?
- Python/Json:Expecting property name enclosed in double quotes
- Displaying better error message than “No JSON object could be decoded”
- JSON to pandas DataFrame
- Displaying better error message than “No JSON object could be decoded”
- Displaying better error message than “No JSON object could be decoded”
- Converting XML to JSON using Python?
- How to get JSON from webpage into Python script
- Loading a file with more than one line of JSON into Pandas
- What is the difference between json.load() and json.loads() functions
- How to convert an XML string to a dictionary?
- NumPy array is not JSON serializable
- ValueError: Expected object or value when reading json as pandas dataframe
- how to read json object in python
- JSON object must be str, bytes or bytearray, not dict
- How to prettyprint a JSON file?
- TypeError: expected str, bytes or os.PathLike object, not _io.TextIOWrapper
- Loading and parsing a JSON file with multiple JSON objects
- set object is not JSON serializable
- dump() missing 1 required positional argument: ‘fp’ in python json
- TypeError: the JSON object must be str, not ‘bytes’
- How to get POSTed JSON in Flask?
- How can I install pip on Windows?
- Best way to convert string to bytes in Python 3?
- Does Python have a string ‘contains’ substring method?
- Difference between import numpy and import numpy as np
- No module named ‘sklearn.cross_validation’
- Maximum and Minimum values for ints
- FileNotFoundError: [Errno 2] No such file or directory [duplicate]
- python capitalize first letter only
- Best way to strip punctuation from a string
- How can I explicitly free memory in Python?
- filename.whl is not supported wheel on this platform
- What is the meaning of [:] in python [duplicate]
- Finding and replacing elements in a list
- socket.error: [Errno 48] Address already in use
- No module named MySQLdb
- TypeError: Missing 1 required positional argument: ‘self’
- Convert a tensor to numpy array in Tensorflow?
- How to import the class within the same directory or sub directory?
- Why do I get AttributeError: ‘NoneType’ object has no attribute ‘something’?
- What is __pycache__?
- Calculating Covariance with Python and Numpy
- What is the easiest way to remove all packages installed by pip?
- In practice, what are the main uses for the new “yield from” syntax in Python 3.3?
- Subplot for seaborn boxplot
- Dump a NumPy array into a csv file
- How to delete a character from a string using Python
- What is the difference between sparse_categorical_crossentropy and categorical_crossentropy?
- Inverse of a matrix using numpy
- NameError: name ‘self’ is not defined
- gaierror: [Errno 8] nodename nor servname provided, or not known (with macOS Sierra)
- Error handling in Python-MySQL
- List files ONLY in the current directory
- No Module Named ‘_pywrap_tensorflow_internal’
- Pop index out of range
- Python script to copy text to clipboard
- How can I check if character in a string is a letter? (Python)
- OSError: Initializing from file failed on csv in Pandas
- ./xx.py: line 1: import: command not found
- How do I run pip on python for windows?
- How to get the text cursor position in Windows?
- python NameError: global name ‘__file__’ is not defined
- Why do I get this error “TypeError: ‘method’ object is not iterable”?
- How to obfuscate Python code effectively?
- Controlling mouse with Python
- can we use XPath with BeautifulSoup?
- how to check which version of nltk, scikit learn installed?
- How do I add two sets?
- Are nested try/except blocks in Python a good programming practice?
- Getting a name error when trying to input a string [duplicate]
- Complex number troubles with numpy
- Running shell command and capturing the output
- Determine if 2 lists have the same elements, regardless of order? [duplicate]
- Python copy files to a new directory and rename if file name already exists
- How to append new data onto a new line
- Building a list inside a list in python
- numpy/scipy/ipython:Failed to interpret file as a pickle
- What is the Python equivalent of static variables inside a function?
- Python – difference between two strings
- Flask-framework: MVC pattern
- Installing win32gui python module