Ainda não tem acesso? Estude com a gente! Matricule-se
Ainda não tem acesso? Estude com a gente! Matricule-se

problemas em rodar o codigo fora do google colab

estou utilizando o visual studio code como IDE toda vez que eu tento rodar o código ele da um erro (vou coloca-lo embaixo do código) poderia me ajudar a faze-lo rodar?

import tweepy as tw
import json
from azure.cognitiveservices.vision.computervision import ComputerVisionClient
from msrest.authentication import CognitiveServicesCredentials

##############chaves twitter########################################
consumer_key = 'B3YWfYbvCexFTn6R86rkoF7e6'
consumer_secret = 'MmF5PKQORyTLC7XzcoLSjZtJtoXDpXbnuVXTp6H0WdCYdzfZaO'
access_token = '1049296684826742784-A8pvWwm8gSni81mXzWT1erUvqCq5iO'
access_token_secret = 'L6S0MLpJjHkieUeCBEsG7NQuzJCEpmH912Awty8Aj6TTA'
####################################################################

##################chaves azure######################################
credenciais = CognitiveServicesCredentials("55b415bb405a41308e9843814e1c5754")
client = ComputerVisionClient("https://westcentralus.api.cognitive.microsoft.com", credenciais)
####################################################################

#######################banco de pesquisa############################
famosos = ['cauareymond','aguiarthur','ivetesangalo','ClaudiaLeitte','neymarjr','BruMarquezine','mariruybarbosa',
'FePaesLeme','Tatawerneck','FlaviaAleReal','julianapaes','dedesecco','SabrinaSato','ahickmann','gusttavo_lima','Anitta',
'CarolCastroReal','gio_antonelli','maisa','cleooficial','gewbank','taisdeverdade','otaviano','bernardipaloma',
'IngridGuimaraes','olazaroramos','GalisteuOficial','debranascimento','FioMattheis','moalfradique','Nandacostareal']
####################################################################


auth = tw.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
api = tw.API(auth)


famosos_id = []

for famoso in famosos:
  famoso_id = api.get_user(famoso).id_str
  famosos_id.append(famoso_id)


class MinhaStreamListener(tw.StreamListener):

  def on_status(self, status):
    print("Usuário:" , status.user.screen_name)
    print("Texto:" ,status.text)

    if 'media' in status.entities:
      url = status.entities['media'][0]['media_url']
      print("URL: ", url)

      analise_celebridades = client.analyze_image_by_domain("celebrities", url, "en")
      lista_celebridades = [celebridade['name'] for celebridade in analise_celebridades.result["celebrities"]]
      print(lista_celebridades)

      descricao = client.describe_image(url,1,"en")
      texto_descricao = descricao.captions[0].text
      print("Descricao: ", texto_descricao)

      analize_de_imagem = client.analyze_image(url,VisualFeatureTypes.tags)
      lista_tags = [tag.name for tag in analize_de_imagem.tags]
      print("Tag: ", lista_tags)

      resultados = {
          'usuario': status.user.screen_name,
          'texto': status.text,
          'url': url,
          'celebridades': lista_celebridades,
          'descricao': texto_descricao,
          'tags': lista_tags
      }

      with open('tweets.txt','a') as arquivo:
        arquivo.write(json.dumps(resultados))
        arquivo.write('\n')



    print('-----')
    print('\n')

    minhaStream = None
    minhaStream = tw.Stream(auth = auth, listener=MinhaStreamListener())
    minhaStream.filter(follow=famosos_id)

o erro a seguir: Traceback (most recent call last): File "/usr/local/lib/python3.6/dist-packages/tweepy/parsers.py", line 48, in parse json = json_lib.loads(payload) AttributeError: module 'json' has no attribute 'loads'

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "avançando_azure.py", line 34, in famoso_id = api.get_user(famoso).id_str File "/usr/local/lib/python3.6/dist-packages/tweepy/binder.py", line 250, in _call return method.execute() File "/usr/local/lib/python3.6/dist-packages/tweepy/binder.py", line 236, in execute result = self.parser.parse(self, resp.text) File "/usr/local/lib/python3.6/dist-packages/tweepy/parsers.py", line 91, in parse json = JSONParser.parse(self, method, payload) File "/usr/local/lib/python3.6/dist-packages/tweepy/parsers.py", line 50, in parse raise TweepError('Failed to parse JSON payload: %s' % e) tweepy.error.TweepError: Failed to parse JSON payload: module 'json' has no attribute 'loads'

1 resposta

Olá Carlos,

vamos garantir primeiro que não é um problema de dependências?

Poderia testar com a versão do python >= 3.6 e tentar instalar o "tweepy" na versão mais atual?