2

嵌入从 Vimeo/Youtube/Dailymotion 提供的视频。我正在使用 oEmbed 标准“抓取”数据。这适用于 Youtube、Dailymotion 和 Soundcloud,但不适用于 Vimeo。我应该通过身份验证来获取这些数据吗?

以下是我如何让它工作。

url = "http://vimeo.com/api/oembed.json?%s" % 
                                      urllib.urlencode({"url": url})
headers = {'User-Agent':  'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)'}
req = urllib2.Request(url, "", headers)
obj = simplejson.loads(urllib2.urlopen(req).read())

作为一个错误,我得到HTTP Error 401: Unauthorized

追溯:

File "/path/to/module/models.py" in save
  87.             obj = simplejson.loads(urllib2.urlopen(req).read())
File "/usr/lib/python2.7/urllib2.py" in urlopen
  126.     return _opener.open(url, data, timeout)
File "/usr/lib/python2.7/urllib2.py" in open
  397.             response = meth(req, response)
File "/usr/lib/python2.7/urllib2.py" in http_response
  510.                 'http', request, response, code, msg, hdrs)
File "/usr/lib/python2.7/urllib2.py" in error
  435.             return self._call_chain(*args)
File "/usr/lib/python2.7/urllib2.py" in _call_chain
  369.             result = func(*args)
File "/usr/lib/python2.7/urllib2.py" in http_error_default
  518.         raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)

有人知道吗?

4

0 回答 0