PythonAnywhere - Authenticated, but halts.

Hi!

I’m having trouble using ASANA API on a PythonAnywhere website, this works perfectly locally, and on their python 3.7 shell.

but, when Ran on the server I can use my API key, and confirm authentication - after that it halts.

import asana


@action('index', method=['GET', 'POST'])
def index():
    user = auth.get_user()
    message = T("Hello {first_name}".format(**user))
    key = "MYKEY"
    asana_api = asana.Client.access_token(key)
    print("asana_api, ",asana_api)
    print(asana_api.session.authorized)
    me = asana_api.users.me()                                 #halts on this line, or any use of the asana_api
    return dict(message=message)

my console logs are

2021-02-08 22:24:37 asana_api, <asana.client.Client object at 0x7f536c5f0750>
2021-02-08 22:24:37 True

and the webpage stalls until it eventually times out.

This will also time out,

for workspace in asana_api.workspaces.find_all():
        print ("workspace, ",workspace)
        workspace_gid = workspace.get('gid')

pretty much any ASANA API call except for the ones shown above will time out…

Thanks so much! Willing to provide any other necessary details

after 5 minutes or so, the logs are:

2021-02-08 22:24:37 asana_api,  <asana.client.Client object at 0x7f536c5f0750>
2021-02-08 22:24:37 True
2021-02-08 22:29:39 Mon Feb  8 22:29:38 2021 - *** HARAKIRI ON WORKER 2 (pid: 8, try: 1) ***
2021-02-08 22:29:39 Mon Feb  8 22:29:38 2021 - HARAKIRI !!! worker 2 status !!!
2021-02-08 22:29:39 Mon Feb  8 22:29:38 2021 - HARAKIRI [core 0] 10.0.0.124 - GET /simpleASANA/index since 1612823077
2021-02-08 22:29:39 Mon Feb  8 22:29:38 2021 - HARAKIRI !!! end of worker 2 status !!!
2021-02-08 22:29:39 DAMN ! worker 2 (pid: 8) died, killed by signal 9 :( trying respawn ...
2021-02-08 22:29:39 Respawned uWSGI worker 2 (new pid: 13)
2021-02-08 22:29:39 spawned 2 offload threads for uWSGI worker 2

This is an issue with web4py mokey-patching requests in a way that is not compatible with how we run code in web apps. We had this from Massimo DiPierro (the author of web4py):

“I tested this and if I comment gevent.monkey.patch_all() from core.py, then pythonanywhere requests works fine for me. gevent is also a problem on google app engine and we are not using it unless we have multiple workers. For now I have eliminated this dependency and picked tornado as default.”

So if you patch your installation of web4py so that it does not call gevent.monkey_patch_all, it should work. Alternatively, it sounds from the above quote like Massimo may have made the change in web4py already, so maybe just updating your installation of web4py will fix it.