我正在尝试在我的虚拟环境中使用{3}}和Python3.3.1。
$ pip freeze
beautifulsoup4==4.4.1
pyembed==1.3.1
requests==2.9.1
但问题是,我得到了Traceback而不是有效的html代码。举个例子:
>>> from pyembed.core import PyEmbed
>>> html = PyEmbed().embed('http://www.youtube.com/watch?v=9bZkp7q19f0')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/jazz/workspace/pillow/venv/lib/python3.3/site-packages/pyembed/core/__init__.py", line 59, in embed
oembed_urls, max_width=max_width, max_height=max_height)
File "/home/jazz/workspace/pillow/venv/lib/python3.3/site-packages/pyembed/core/consumer.py", line 57, in get_first_oembed_response
raise PyEmbedConsumerError('No valid OEmbed responses for URLs %s' % oembed_urls)
pyembed.core.consumer.PyEmbedConsumerError: No valid OEmbed responses for URLs <generator object get_oembed_urls at 0xb724b5a4>
>>>
我使用任何有效的youtube链接获取此Traceback。奇怪的是,它昨天有用......任何想法有什么不对?提前谢谢......
答案 0 :(得分:0)
看起来Youtube阻止了pyembed的默认用户代理:
In [7]: requests.get('http://www.youtube.com/watch?v=9bZkp7q19f0')
Out[7]: <Response [503]>
In [8]: headers = { 'User-Agent': 'Mozilla/5.0' }
In [9]: requests.get('http://www.youtube.com/watch?v=9bZkp7q19f0', headers=headers)
Out[9]: <Response [200]>