import json
json_data = json.loads(data)
print(json_data)
in this code
import json
json_data = json.loads(data)
print(json_data)
in this code
Hi,
What error this code is throwing?
what is data variable here? check the data variable before parsing it to json object. The API should return a successful response Then only you can use json.loads()
on data .
can u tell me how to share .ipynb file?
how to get code from jupyter?
Either copy paste your cells, or download the file as .py
from urllib.request import urlopen
api_url = “https://samples.openweathermap.org/data/2.5/weather?q=London,uk&appid=b6907d289e10d714a6e88b30761fae22”
url_result = urlopen(api_url)
print(url_result)
data = url_result.read()
print(type(data))
import json
json_data = json.loads(data) ## i m getting error here
print(json_data)
ya bro thats what i was asking as i was getting error here why?? any reason why json not working on my machine?
Please post the screenshot of the error. What is the error you are getting.
actually currently i m using my friends pc and jupyter is not there in this so i m sharing the error?hope this might work
I hope you are working on >=python 3.6.
If not, try to decode the bytes to string using this:
json.loads(data.decode('utf-8'))
i m having python 3.5.2 shall i change it or is it ok for future work during the cource?
It would be great, if you work with latest version of python.
Since, they are putting more inbuilt features in python. Otherwise you have to explicitly handle some cases where you get error coz of python version like in this case
i just need to install latest anaconda navigator and uninstall this one ?
Yes, you can do this way as well. Anaconda is also a good package manager.
But Dont forget to check on add Python to my Path - Environment Variables
isnt there any direct update ?
I guess this is not possible, though we can upgrade the pip, but I Never tried to upgrade the python.
So, either you can google this. or do the method discussed above.
i updated to python 3.7.4 but even now same error but its working with json.loads(data.decode(‘utf-8’))
can u tell where is the problem?