使用我从this tutorial获得的代码,我试图从Python创建twitter bot来转发任何带有特定关键字的tweet。它使用pythontwitter开发人员和Redis提供的python-twitterAPI包装器。我已经安装并获得了wrapper和Redis,它们运行起来没有问题,但是当我运行twit时_机器人.py从命令行中,我得到以下错误:
Traceback (most recent call last):
File "twit_bot.py", line 116, in <module>
twitter_session = auth_to_twitter(API_CREDENTIALS)
File "twit_bot.py", line 27, in auth_to_twitter
api = twitter.Api(consumer_key=api_credentials['consumer_key'],
AttributeError: 'module' object has no attribute 'Api'
This is a pastebin with my bot.我是一个完全的python新手,真的不知道如何解决这个问题。在
从上面的pastebin中,我从第27行复制到第36行:
^{pr2}$更新:新错误
按照用户Bibhas的建议,在运行pip freeze
并卸载路径中的额外twitter包装之后,我运行twit_机器人.py在命令行中,我仍然收到一个错误,这一次如下所示:
Traceback (most recent call last):
File "twit_bot.py", line 118, in <module>
run_bot(twitter_session, redis, TWITTERBOT_KEYWORDS)
File "twit_bot.py", line 108, in run_bot
update_search_stack(api_session, redis, key)
File "twit_bot.py", line 65, in update_search_stack
since_id = get_since_id(redis, "%s:%s" % (TWITTERBOT_LIST, keyword))
File "twit_bot.py", line 41, in get_since_id
since_id = redis.get(key + ":last_since_id")
File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/redis/client.py", line 585, in get
return self.execute_command('GET', name)
File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/redis/client.py", line 381, in execute_command
connection.send_command(*args)
File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/redis/connection.py", line 304, in send_command
self.send_packed_command(self.pack_command(*args))
File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/redis/connection.py", line 286, in send_packed_command
self.connect()
File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/redis/connection.py", line 234, in connect
raise ConnectionError(self._error_message(e))
redis.exceptions.ConnectionError: Error 61 connecting localhost:6379. Connection refused.
再次更新!
因为看起来Redis服务器是给我带来问题的服务器(
redis.exceptions.ConnectionError: Error 61 connecting localhost:6379. Connection refused.
),如上面的错误所示,我查看了this stackoverflow question,希望得到一个潜在的答案,但是进入python控制台并运行
>>> import redis
>>> print redis.Redis("localhost")
<redis.client.Redis object at 0x10e5480d0>
>>>
没有给我任何有用的东西,因为它说它是连接的(我想!?!?!)所以我还是不知道如何解决这个问题,这样我的机器人才能正常工作。:C
def run_bot(api_session, redis, keywords):
""""""
while 42:
for key in keywords:
update_search_stack(api_session, redis, key)
update_since_id(redis, "%s:%s" % (TWITTERBOT_LIST, key))
tweet_and_shout(api_session, redis, key, timeout=1)
print "Waiting for one minute\n\n\n"
sleep(60)
if __name__ == "__main__":
twitter_session = auth_to_twitter(API_CREDENTIALS)
redis = redis.Redis("localhost")
run_bot(twitter_session, redis, TWITTERBOT_KEYWORDS)
目前没有回答
相关问题 更多 >
编程相关推荐