Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Garph from reddit's example code for importing JSON
- import JSON
- from urllib import requests
- def getJSON(url):
- # Retrieves JSON data from a website
- # error handling included for invalid URLs
- try:
- stream = request.urlopen(url)
- if stream.getcode() == 200:
- data = stream.read()
- data = data.decode("utf-8")
- return json.loads(data)
- else:
- print("URL Unsucessful")
- except request.HTTPError:
- print("Invalid URL")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement