Forums

gtts not working with some tld's

When using gTTS on Pythonanywhere, with a command such as:

audio1 = gTTS(text=’text to be read’, lang=’es’, tld=’com.mx’, slow=False)

I get a message:

“gTTSError”

“Failed to connect. Probable cause: Host 'https://translate.google.com.mx/' is not reachable”

The error is “tld” dependent. tld=’com’ works, tld=’com.mx’ or tld=’com.br’ does not. The exact same code works, without errors on other systems, just not on Pythonanywhere.

Does Pythonanywhere block access to some countries, or is there another explanation of why the code works on other systems, but not on Pythonanywhere. (This is not an intermittent problem, certain tld’s never work on Pythonanywhere, but always work on other systems (same code). The Python (Python 3.1.3) and gtts (gTTS 2.5.4) versions used are the same on Pythonanywhere and on the systems that work.

Free accounts on PythonAnywhere can only access the sites that are on our allowlist. Normally we would ask you to submit a request at this page to add on new sites, but the various country-code domains of Google are a special case -- so I've added their .com.mx and .com.br sites now. Let us know if there are any other Google domains that you'd like to have added.