Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import urllib
- import json
- request = urlopen("http://api.exmaple.com/stuff?client_id=someid&client_secret=randomsecret")
- response = request.read()
- json = json.loads(response)
- if json['success']:
- ob = json['response']['ob']
- print ("The current weather in Seattle is %s with a temperature of %d") % (ob['weather'].lower(), ob['tempF'])
- else:
- print ("An error occurred: %s") % (json['error']['description'])
- request.close()
- Traceback (most recent call last):
- File "thing.py", line 4, in <module>
- request = urlopen("http://api.exmaple.com/stuff?client_id=someid&client_secret=randomsecret")
- NameError: name 'urlopen' is not defined
- from urllib.request import urlopen
- req = urlopen(...)
- import urllib.request
- req = request.urlopen(...)
- from urllib import urlopen
- import urllib
- import json
- request = urllib.urlopen("http://api.exmaple.com/stuff?client_id=someid&client_secret=randomsecret")
- response = request.read()
- json = json.loads(response)
- if json['success']:
- ob = json['response']['ob']
- print ("The current weather in Seattle is %s with a temperature of %d") % (ob['weather'].lower(), ob['tempF'])
- else:
- print ("An error occurred: %s") % (json['error']['description'])
- request.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement