Gmail API does not work/Too slow

I get absolutely no response when I go onto my site for the Gmail API.

There are no errors. After exactly 259 seconds, my site returns a "Something went wrong" page. This script works perfectly on my laptop in a single second.

If this has something to do with PythonAnywhere's speed because I'm on a free trial, I'm not convinced that upgrading to a new plan will solve my issue as much, given the extremely slow speed.

Any ideas? Are there 24 hour trials for the hacker plan for example?

What exact code are you using to connect to Gmail (apart from any passwords, of course)? We have a special exception to the firewall rules for free accounts, so that they can connect to Gmail directly.

I'm using these libraries:

google-api-python-client google-auth-httplib2 google-auth-oauthlib

If you get a "Something went wrong" page, then there should be a traceback in your error log or some sort of message in your server log that we can use to help you debug it.

The 259 seconds and then an error suggest that something in the library is timing out and causing the error.

Yes I checked the error log, and I found out that the response time is 259 seconds, but no errors.

The question is whether there is a firewall blocking me from using Google Cloud APIs or not.

Nothing on our side.

I put a print statement here, and it doesn't print out when I visit the main page of my site/API.


def hello_world():

Could that have something to do with it?

It should be printing it to stdout that goes to the server log. (You will find links to logs on your "Web" page.)

Did you solved this issue? I have same problems . Is there something to do with PythonAnywhere's speed because of a free trial?

No, you should be able to quickly send emails on the free version. What code are you using to send the message, and what happens when it runs?

Hi. I used sendemail function at the below link.

I think it may be the "asynchronous" aspect that is causing problems. It's probably trying to use threads, which are disallowed in website code on PythonAnywhere. If you just use the normal Django send_mail function it will work much better.

Thanks. You mean the all asynchronous functions is not allowed on PythonAnywhere?

Threads are not allowed in website code, but they can be used elsewhere (for example, in consoles, or scheduled tasks). So you can use various tricks to offload async tasks to other parts of the system -- see this help page. Caveat: the best ways to do that kind of thing require a paid account.