Python 2.7: Program does not run [closed]

0

Hello, My program is no longer running, it used to work normally but then it just does not work. I checked that the program is no more than the "reload (sys)" line.

# -*- coding: cp1252 -*-
from gtts import gTTS as gtts
import sys
reload(sys);
sys.setdefaultencoding('utf-8');

def audio_br(words, mp3name, language="pt"):
  teste= gtts(text=words,lang=language);
  teste.save("%s.mp3" % mp3name);

audio_br("Segundo ao portal New York times sobre política no Brazil temos","padrão_");
audio_br("Segundo ao portal Catraca Livre sobre tecnologia temos","padrão_a");
audio_br("Segundo ao portal Partiu Intercâmbio sobre bolsas de estudos temos","padrão_b");
audio_br("Segundo ao portal Estudar Fora sobre bolsas de estudos temos","padrão_c");
    
asked by anonymous 09.07.2017 / 17:01

1 answer

2

I have exactly Python 2.7 installed on my machine, the semicolons did not affect the operation , the only error I had was:

  

No module named gtts

This is because I did not have the module installed, so I installed it via pip in cmd (I'm using Windows):

pip install gTTS

The result was:

Seethepossibleerrors

Thefilesarebeingsavedinanotherfolder

Yourscriptifitisrunforexample:

c:\Users\user>pythonc:\exemplos\python\script.py

Itwillsavethe.mp3inthec:\Users\userfolderandnotinthec:\exemplos\pythonfolder

Orso(unix-like):

eu@debian:~$python/home/usuario/exemplos/python/script.py

Itwillsavethe.mp3inthe/home/[usuario]folder(~$indicatesthehomeoftheuser)andnotinthe/home/usuario/exemplos/pythonfolder

Thenitsavesfromwhereitexecuted.

Lackofwritingpermission

Maybethelocationwhereyouaretryingtosavethefilesdoesnothavewritepermission,itdependsalotonwhereyouaretryingtorunandtheoperatingsystem,ifyour.pyisforexampleinthec:\ProgramsandFilesfolderitwillnotwritethe.mp3unlessyouhaveadministrativemode,ofcourseifyouaretryingtorunfromthatfolder.

Coding

Ifyour.pyissavedwithanencodingotherthanutf-8itmightcausethiserror:

Traceback(mostrecentcalllast):File"tests/n.py", line 12, in <module>
    audio_br("Segundo ao portal New York times sobre polÝtica no Brazil temos","
padrÒo_");
  File "tests/n.py", line 9, in audio_br
    teste= gtts(text=words,lang=language);
  File "C:\Python27\lib\site-packages\gtts\tts.py", l
ine 94, in __init__
    if self._len(text) <= self.MAX_CHARS:
  File "C:\Python27\lib\site-packages\gtts\tts.py", l
ine 154, in _len
    return len(text.decode('utf8'))
  File "C:\Python27\lib\encodings\utf_8.py", line 16,
 in decode
    return codecs.utf_8_decode(input, errors, True)
UnicodeDecodeError: 'utf8' codec can't decode byte 0xed in position 42: invalid
continuation byte

This is because lib apparently works with utf-8.

    
10.07.2017 / 04:46