2016-04-13 40 views
0

我想在我的虛擬環境中使用pyembed和Python3.3.1。pyembed不起作用

$ 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鏈接。奇怪的是,它昨天工作...任何想法有什麼不對?在此先感謝...

回答

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]> 
+0

問題由pyembed == 1.3.3解決,現在一切工作正常。 –