2014-11-09 12 views
5

Sto eseguendo il programma di seguito. Ma sto ricevendo il messaggio di errore qui sotto. 401 **** **** (mantiene a ripetere)401 errore durante l'utilizzo di tweepy

Il codice (ottenuto da alcuni forum) cerca sostanzialmente di connettersi a Twitter e prendere tweet. Quando viene eseguito su terminale Ubuntu appare il messaggio di errore 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

Stai utilizzando i tuoi token di accesso/consumatore corretti? Non solo quelli da "alcuni forum" o "" XX "'? – Luigi

+0

Sto usando quelli corretti che ho generato dal sito di sviluppatori di Twitter –

risposta

5

Ecco come funziona .. !!!

  • Twitter registra l'ora corrente.
  • Se una richiesta API per l'autenticazione proviene da un server che afferma che si tratta di un periodo di tempo non compreso tra 15 minuti del tempo di Twitter, fallirà con un errore 401.

Basta resettare l'orologio del sistema in base all'orologio mondiale o lasciarlo governare da internet il problema verrà risolto.

Buona fortuna .. !!!

+0

Grazie ... provo ... :-) –

+0

Hellow come posso farlo su Ubuntu 14.10 –

+0

Vai a Impostazioni e imposta il tuo orologio secondo il fuso orario globale. – mark922

Problemi correlati