tweepy错误python 2.7
我不断地发现这个错误:tweepy错误python 2.7,python,python-2.7,tweepy,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 = '
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!"
导入套接字
从urllib2导入urlopen、URLError、HTTPError
socket.setdefaulttimeout(23)#超时(秒)
url='1〕http://google.co.uk'
尝试:
响应=urlopen(url)
除HTTPError外,e:
tweet_text=“Raspberry Pi服务器已关闭!”
textfile=open('/root/Documents/server_check.txt',w')
textfile.write(“down”)
textfile.close()
除URLError外,e:
tweet_text=“Raspberry Pi服务器已关闭!”
textfile=open('/root/Documents/server_check.txt',w')
textfile.write(“down”)
textfile.close()
其他:
textfile=open('/root/Documents/server_check.txt',r')
如果“down”处于打开状态('/root/Documents/server_check.txt')。read():
tweet_text=“Raspberry Pi服务器已启动!”
textfile=open('/root/Documents/server_check.txt',w')
textfile.write(“up”)
textfile.close()
如果打开('/root/Documents/server_check.txt')中出现“up”。read():
tweet_text=“”
如果len(tweet_text)问题是tweepy不允许您将同一条tweet推两次,因此为了修复它,我添加了以下代码行:
for status in tweepy.Cursor(api.user_timeline).items():
try:
api.destroy_status(status.id)
except:
pass
上面的代码删除了以前的tweet,这样我的下一条tweet就不会失败
我希望这对其他人有帮助 小心,这会破坏你所有的推文“tweepy不会让你两次推同一条推文”这是不准确的;Twitter不允许重复推文。Tweepy继承了Twitter API的限制。使用哪个API库并不重要。