当我尝试反复运行代码时,我有时会随机出错
File "C:\Users\xxxx\Desktop\Startup\twitterapi.py", line 54, in <module>
twitterStream.filter(track=["asdfqw"])
File "C:\Python27\lib\site-packages\tweepy\streaming.py", line 430, in filter
self._start(async)
File "C:\Python27\lib\site-packages\tweepy\streaming.py", line 346, in _start
self._run()
File "C:\Python27\lib\site-packages\tweepy\streaming.py", line 286, in _run
raise exception
TypeError: cannot concatenate 'str' and 'int' objects
有时代码工作正常,有时它不会。当我重新运行它几次它最终工作。可能是什么问题?我的代码或tweepy有问题吗? 这是我的代码
class listener(StreamListener):
def on_data(self, data):
tweet = json.loads(data);
#print json.dumps(tweet, indent=4, sort_keys=True)
#print tweet['text']
try:
tweetid = tweet['id_str']
print tweetid
except:
try:
tweetid = tweet['id']
except:
pass
try:
userid = tweet['user']['id_str']
except:
pass
try:
text = tweet['text']
except:
pass
cur.execute(r"INSERT INTO twitterfeeds(tweet_id, user_id,body,status) VALUES (%s, %s, %s, '0')",(tweetid, userid, text))
db.commit()
#print "pass"
return True
def on_error(self, status):
print "Error: " + status
#while True:
# try:
auth = OAuthHandler(ckey, csecret)
auth.set_access_token(atoken, asecret)
twitterStream = Stream(auth, listener())
twitterStream.filter(track=["asdfqw"])
# except:
# pass
答案 0 :(得分:1)
替换:
DropDownListFor
与
print "Error: " + status