您好我在尝试在Ubuntu中运行脚本以从Twitter发送推文时收到以下错误。我是编程的新手,我不明白什么是错的。我已经做过sudo apt-get install python-twitter和sudo apt-get upgrade。
computer@ubuntu:~/Desktop/Twitter/examples$ python stream_tweets.py
Traceback (most recent call last):
File "stream_tweets.py", line 1, in <module>
from TwitterAPI import TwitterAPI
File "/usr/local/lib/python2.7/dist-packages/TwitterAPI/TwitterAPI.py", line 10, in <module>
from requests.packages.urllib3.exceptions import ReadTimeoutError, ProtocolError
ImportError: cannot import name ReadTimeoutError
答案 0 :(得分:1)
我找到了答案!我所要做的就是更新请求并且它正在工作!
pip install --upgrade requests
安装请求它的pip安装请求
答案 1 :(得分:0)
我想你可能在看错了。当您将python-twitter
安装为Ubuntu软件包时,它与使用python-twitter
Python软件包不同。为了确认这一点,我列出了实际的Ubuntu包内容。我正在运行Ubuntu 12.04.5 LTS版本:
tbates@ubuntu-desktop-1:~$ dpkg-query -L python-twitter
/.
/usr
/usr/bin
/usr/bin/tweet
/usr/bin/twitter-to-xhtml
/usr/share
/usr/share/doc
/usr/share/doc/python-twitter
/usr/share/doc/python-twitter/twitter.html
/usr/share/doc/python-twitter/copyright
/usr/share/doc/python-twitter/changelog.Debian.gz
/usr/share/man
/usr/share/man/man1
/usr/share/man/man1/tweet.1.gz
/usr/share/man/man1/twitter-to-xhtml.1.gz
/usr/share/pyshared
/usr/share/pyshared/python_twitter-0.6.egg-info
/usr/share/pyshared/python_twitter-0.6.egg-info/dependency_links.txt
/usr/share/pyshared/python_twitter-0.6.egg-info/SOURCES.txt
/usr/share/pyshared/python_twitter-0.6.egg-info/top_level.txt
/usr/share/pyshared/python_twitter-0.6.egg-info/requires.txt
/usr/share/pyshared/python_twitter-0.6.egg-info/PKG-INFO
/usr/share/pyshared/twitter.py
/usr/share/python-support
/usr/share/python-support/python-twitter.public
执行man tweet
似乎表明此程序包提供了用于发送推文的命令行工具,而不是如何流式传输推文。
如果您打算使用python-twitter
软件包,建议您按照位于https://github.com/bear/python-twitter的GitHub存储库中的说明进行操作。如果你想使用流媒体API,我自己也没有这样做,但有一篇很棒的文章,我发现在http://adilmoujahid.com/posts/2014/07/twitter-analytics/讨论如何做到这一点。看起来Twitter的文档非常普遍,并且非常规范或清楚如何“只做它”,所以你并不孤单!希望这会有所帮助。