I want to retrieve and work with basic Vimeo data in python 3.2, given a video's URL. I'm a newcomer to JSON (and python), but it looked like the right fit for doing this.
- Request Vimeo video data (via an API-formatted .json URL)
- Convert returned JSON data into python dict
- Display dict keys & data ("id", "title", "description", etc.)
Another SO page Get json data via url and use in python did something similar in python 2.x, but syntax changes (like integrating urllib2) led me to try this.
>>> import urllib
>>> import json
>>> req = urllib.request.urlopen("http://vimeo.com/api/v2/video/31161781.json")
>>> opener = urllib.request.build_opener()
>>> f = opener.open(req)
Traceback (most recent call last):
File "<pyshell#28>", line 1, in <module>
f = opener.open(req)
File "C:\Python32\lib\urllib\request.py", line 358, in open
protocol = req.type
AttributeError: 'HTTPResponse' object has no attribute 'type'
This code will integrate into an existing project, so I'm tied to using python. I know enough about HTTP queries to guess the data's within that response object, but not enough about python to understand why the open failed and how to reference it correctly. What should I try instead of opener.open(req)
?