2014-11-09 9 views
5

아래 프로그램을 실행하고 있습니다. 아래 오류 메시지가 표시됩니다. 401 **** 401 **** 이tweepy를 사용하는 동안 401 오류가 발생했습니다.

(일부 포럼에서 가져온) 코드는 기본적으로 트위터에 연결하고 트윗을 가져 오기 위해 시도 (반복에 계속). 우분투 터미널에서 실행되었을 때 401 오류 메시지가 나타납니다.

import sys 
import json 
import pymongo 
import tweepy 
consumer_key="XX" ##all the keys and codes have to be strings 
consumer_secret="XX" 
access_token = "XX" 
access_token_secret = "XX" 
# This is the listener, resposible for receiving data 

class StdOutListener(tweepy.StreamListener): 

    def on_data(self, data): 

     # Twitter returns data in JSON format - we need to decode it first 

     decoded = json.loads(data) 



     # Also, we convert UTF-8 to ASCII ignoring all bad characters sent by users 

     print '@%s: %s' % (decoded['user']['screen_name'], decoded['text'].encode('ascii', 'ignore')) 

     print '' 

     return 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 all new tweets for #programming:" 



    # There are different kinds of streams: public stream, user stream, multi-user streams 

    # In this example follow #programming tag 

    # For more details refer to https://dev.twitter.com/docs/streaming-apis 

    stream = tweepy.Stream(auth, l) 

    stream.filter(track=['programming']) 
+0

정확한 소비자/액세스 토큰을 사용하고 있습니까? "some forum"또는 "XX"'의 사람들뿐 아니라? – Luigi

+0

트위터 개발자 사이트에서 생성 된 올바른 것들을 사용하고 있습니다 –

답변

5

이것이 작동하는 방식입니다. !!!

  • 트위터가 현재 시간을 추적합니다.
  • 인증을위한 API 요청이 트위터 시간 15 분이 아닌 시간이라고 주장하는 서버에서 온 경우, 401 오류와 함께 실패합니다.

세계 시계에 따라 시스템 시계를 재설정하거나 인터넷을 통해 문제를 해결하면 문제가 해결됩니다.

행운을 빌어 요 !!!

+0

고마워요 ... 시도해 보겠습니다 ...--) –

+0

우분투에서 어떻게 할 수 있습니까? 14.10 –

+0

설정으로 이동하여 시계를 설정하십시오. 전역 표준 시간대. – mark922

관련 문제