python - tweepy 错误 python 2.7

标签 python python-2.7 tweepy

我一直收到这个错误:

tweepy.error.TweepError: [{u'message': u'Status is a duplicate.', u'code': 187

我不知道为什么我会收到这个错误我已经尝试了所有方法!

我的主要代码是:

import socket
from urllib2 import urlopen, URLError, HTTPError

socket.setdefaulttimeout( 23 )  # timeout in seconds

url = 'http://google.co.uk'
try :
    response = urlopen( url )
except HTTPError, e:
    tweet_text = "Raspberry Pi Server is DOWN!"
    textfile = open('/root/Documents/server_check.txt','w')
    textfile.write("down")
    textfile.close()
except URLError, e:
    tweet_text = "Raspberry Pi Server is DOWN!"
    textfile = open('/root/Documents/server_check.txt','w')
    textfile.write("down")
    textfile.close()
else :
    textfile = open('/root/Documents/server_check.txt','r')
    if 'down' in open('/root/Documents/server_check.txt').read():
        tweet_text = "Raspberry Pi Server is UP!"
        textfile = open('/root/Documents/server_check.txt','w')
        textfile.write("up")
        textfile.close()
    elif 'up' in open('/root/Documents/server_check.txt').read():
        tweet_text = ""
if len(tweet_text) <= 140:
    if tweet_text == "Raspberry Pi Server is DOWN!" or tweet_text == "Raspberry Pi Server is UP!":
        api.update_status(status=tweet_text)
    else:
        pass
else:
    print "Your message is too long!"

出于安全原因,我删除了 API!我还删除了指向我的服务器的链接。 任何帮助将不胜感激!

谢谢

最佳答案

问题是 tweepy 不允许你将同一条推文发两次,所以为了修复它我添加了这些代码行:

for status in tweepy.Cursor(api.user_timeline).items():
    try:
        api.destroy_status(status.id)
    except:
        pass

上面的代码删除了之前的推文,这样我的下一条推文就不会失败。

我希望这对其他人有帮助!

关于python - tweepy 错误 python 2.7,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29635085/

相关文章:

python - 如何在 Pandas 中的后续行之间进行操作?

Python从元组列表中生成字典列表

Python/Tweepy UnicodeEncodeError

python - 导入父模块和子模块

python - 具有两个关键数据帧的堆积条形图

python:文本文件处理,for循环和read操作冲突

python - 如何使用 Python ftplib 获取 FTP 文件的修改时间

python - + : 'int' and 'list' - python 不受支持的操作数类型

twitter - Tweepy 错误 104 : Connection aborted

python - 查看哪个 Python 类正在使用我的 100% CPU?