Skip to content

Instantly share code, notes, and snippets.

@meskarune
Created June 10, 2013 21:54
Show Gist options
  • Save meskarune/5752741 to your computer and use it in GitHub Desktop.
Save meskarune/5752741 to your computer and use it in GitHub Desktop.
Get weather data using Wunderground API
python test.py
Traceback (most recent call last):
File "test.py", line 10, in <module>
response = json.load(urllib.request.urlopen(request))
File "/usr/lib/python3.3/json/__init__.py", line 274, in load
parse_constant=parse_constant, object_pairs_hook=object_pairs_hook, **kw)
File "/usr/lib/python3.3/json/__init__.py", line 319, in loads
return _default_decoder.decode(s)
File "/usr/lib/python3.3/json/decoder.py", line 352, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
TypeError: can't use a string pattern on a bytes-like object
#!/usr/bin/python
import json
import urllib.request
url = "http://api.wunderground.com/api/<API HERE>/conditions/q/nj/galloway.json"
request = urllib.request.Request(url)
response = json.load(urllib.request.urlopen(request))
print (json.dumps(response,indent=2))
@meskarune
Copy link
Author

works:

!/usr/bin/python

import json
from urllib import request

url = "http://api.wunderground.com/api//conditions/q/nj/galloway.json"

request = request.urlopen(url)

encoding = request.headers.get_content_charset()
data = json.loads(request.read().decode(encoding))

print (json.dumps(data,indent=2))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment