Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

1.1K
Visualizações
No se puede importar StreamListener

Estoy tratando de crear un flujo de datos en Python usando la API de Twitter, pero no puedo importar StreamListener correctamente.

Aquí está mi código:

 import tweepy from tweepy import Stream from tweepy.streaming import StreamListener class MyListener(StreamListener): def on_data(self, data): try: with open('python.json', 'a') as f: f.write(data) return True except BaseException as e: print("Error on_data: %s" % str(e)) return True def on_error(self, status): print(status) return True twitter_stream = Stream(auth, MyListener()) twitter_stream.filter(track=['#python'])

Y estoy recibiendo este error:

 Traceback (most recent call last): File "c:\Users\User\Documents\GitHub\tempCodeRunnerFile.python", line 6, in <module> from tweepy.streaming import StreamListener ImportError: cannot import name 'StreamListener' from 'tweepy.streaming' (C:\Users\User\AppData\Local\Programs\Python\Python39\lib\site-packages\tweepy\streaming.py)
over 4 years ago · Santiago Trujillo
3 Respostas
Responde à pergunta

0

Tweepy v4.0.0 se lanzó ayer y fusionó StreamListener en Stream .

Recomiendo actualizar su código a la subclase Stream en su lugar.
Alternativamente, puede cambiar a la versión 3.10.0.

over 4 years ago · Santiago Trujillo Relatório

0

Para Tweepy v4 , no necesita usar StreamListener . El siguiente es un código editado para v4:

 import tweepy class MyListener(tweepy.Stream): def on_data(self, data): try: with open('python.json', 'a') as f: f.write(data) return True except BaseException as e: print("Error on_data: %s" % str(e)) return True def on_error(self, status): print(status) return True twitter_stream = MyListener( "Consumer Key here", "Consumer Secret here", "Access Token here", "Access Token Secret here" ) twitter_stream.filter(track=['#python'])
over 4 years ago · Santiago Trujillo Relatório

0

Un ligero ajuste arreglará esto

 #from tweepy.streaming import StreamListener #OLD CODE import tweepy # NEW CODE #class TweetListener (StreamListener): #OLD CODE class TweetListener (tweepy.Stream): # NEW CODE
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda