Saturday, 15 August 2015

python 2.7 - 401 error while using tweepy -



python 2.7 - 401 error while using tweepy -

i running below program.but getting below error message. 401 **** 401 **** (keeps on repeating)

the code(got forum) tries connect twitter , fetch tweets. when ran on ubuntu terminal 401 error message appear.

import sys import json import pymongo import tweepy consumer_key="xx" ##all keys , codes have strings consumer_secret="xx" access_token = "xx" access_token_secret = "xx" # listener, resposible receiving info class stdoutlistener(tweepy.streamlistener): def on_data(self, data): # twitter returns info in json format - need decode first decoded = json.loads(data) # also, convert utf-8 ascii ignoring bad characters sent users print '@%s: %s' % (decoded['user']['screen_name'], decoded['text'].encode('ascii', 'ignore')) print '' homecoming true def on_error(self, status): print status if __name__ == '__main__': l = stdoutlistener() auth = tweepy.oauthhandler(consumer_key, consumer_secret) auth.set_access_token(access_token, access_token_secret) print "showing new tweets #programming:" # there different kinds of streams: public stream, user stream, multi-user streams # in illustration follow #programming tag # more details refer https://dev.twitter.com/docs/streaming-apis stream = tweepy.stream(auth, l) stream.filter(track=['programming'])

this how works..!!!

twitter keeps track of current time. if api request authenticate comes server claims time outside of 15 minutes of twitter time, fail 401 error.

just reset system's clock according world clock or allow rule net problem solved.

good luck..!!!

python-2.7 tweepy http-status-code-401

No comments:

Post a Comment