Requests fail in a simple py4web app running on a paid PythonAnywhere account

330 views
Skip to first unread message

Aubrey Moore

unread,
Oct 16, 2020, 8:55:15 PM10/16/20
to py4web
Not sure if this is a py4web problem or a PythonAnywhere problem, but I would really
appreciate any advice on debugging/fixing it.

I built a very simple py4web app on PythonAnywhere using the Minimal app template.
It is hosted on my paid PA account at aubreymoore.pythonanywhere.com/minimal
When I request the "index" route, I get the expected result, "Hello World".
However, when I request "test_req" or "test_urllib", the browser hangs for about
ten minutes and then returns "Something went wrong :-( ... Error code: 504-loadbalancer".
There are no records added to the PA error log, but the PA server log indicates that
the app commits harakiri and dies after announcing loyalty to the emporer (See below.)

minimal/__init__.py

from py4web import action
import requests
import urllib.request

@action("index")
def index():
   
return "Hello World"
   
@action('test_req')
def test_req():
   
return requests.get('https://pythonanywhere.com').text
   
@action('test_urllib')
def test_urllib():
   
return urllib.request.urlopen("http://pythonanywhere.com").read()

PythonAnywhere Server log

2020-10-17 00:19:50 announcing my loyalty to the Emperor...
2020-10-17 00:26:03 Sat Oct 17 00:26:02 2020 - *** HARAKIRI ON WORKER 2 (pid: 15, try: 1) ***
2020-10-17 00:26:03 Sat Oct 17 00:26:02 2020 - HARAKIRI !!! worker 2 status !!!
2020-10-17 00:26:03 Sat Oct 17 00:26:02 2020 - HARAKIRI [core 0] 10.0.0.124 - GET /minimal/test_urllib since 1602894061
2020-10-17 00:26:03 Sat Oct 17 00:26:02 2020 - HARAKIRI !!! end of worker 2 status !!!
2020-10-17 00:26:03 DAMN ! worker 2 (pid: 15) died, killed by signal 9 :( trying respawn ...
2020-10-17 00:26:03 Respawned uWSGI worker 2 (new pid: 18)
2020-10-17 00:26:03 spawned 2 offload threads for uWSGI worker 2






Abdoul salam

unread,
Oct 29, 2020, 1:09:58 AM10/29/20
to py4web
I've had similar problem few months back. Seems not supported for now and no one will want to talk about. Even the SMTP wasn't working. 

My advice:
If your project has a deadline, port back to web2py till it becomes a priority

Massimo

unread,
Oct 30, 2020, 12:19:16 AM10/30/20
to py4web
I tried this on my python anywhere account:

mkdir apps
mkdir apps/test
echo "" > apps/__init__.py
echo > apps/test/__init__.py << EOF
from py4web import action
import requests
import urllib.request

@action("index")
def index(): return "Hello World\n"

@action('test_requests')
def test_req(): return requests.get('https://pythonanywhere.com').text

@action('test_urllib')
def test_urllib(): return urllib.request.urlopen("http://pythonanywhere.com").read()
EOF

py4web run apps --port 8001 > apps.log

It worked fine. Can you try on yours?

Aubrey Moore

unread,
Oct 30, 2020, 2:55:00 AM10/30/20
to Massimo, py4web
Sorry for being such a newbie.

Working in a bash console, everything goes fine until I launch the server:
command: py4web run apps --port 8001 > apps.log
response: .. Listening on http://127.0.0.1:8001/

When I enter:
Nothing happens.

When I open a new bash console and re-enter the curl command, I get:
Failed to connect to 127.0.0.1 port 8001: Connection refused

What am I missing?


--
You received this message because you are subscribed to the Google Groups "py4web" group.
To unsubscribe from this group and stop receiving emails from it, send an email to py4web+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/py4web/fdc6cccf-4e7c-4c9d-9a02-c80bdda9da86n%40googlegroups.com.

Massimo DiPierro

unread,
Oct 30, 2020, 3:08:29 AM10/30/20
to Aubrey Moore, py4web
will create a file 1.txt and it should contain the web page.
Let me know if it does or not.

It may be ok that does not work from another console. Different consoles may run on different vms.

Abdoul salam

unread,
Oct 30, 2020, 5:49:03 AM10/30/20
to py4web
SMTP!!! 

Error Ticket: database is locked
Traceback (most recent call last): File "/home/halal/.virtualenvs/venv/lib/python3.7/site-packages/py4web/core.py", line 734, in wrapper ret = func(*func_args, **func_kwargs) File "/home/halal/.virtualenvs/venv/lib/python3.7/site-packages/py4web/core.py", line 694, in wrapper ret = func(*args, **kwargs) File "/home/halal/.virtualenvs/venv/lib/python3.7/site-packages/py4web/core.py", line 694, in wrapper ret = func(*args, **kwargs) File "/home/halal/.virtualenvs/venv/lib/python3.7/site-packages/py4web/utils/auth.py", line 677, in _ return dict(form=form_factory(), path=path, **env) File "/home/halal/.virtualenvs/venv/lib/python3.7/site-packages/py4web/utils/auth.py", line 942, in request_reset_password self.auth.request_reset_password(email, send=True, next="") File "/home/halal/.virtualenvs/venv/lib/python3.7/site-packages/py4web/utils/auth.py", line 410, in request_reset_password user.update_record(action_token="reset-password-request:" + token) File "/home/halal/.virtualenvs/venv/lib/python3.7/site-packages/pydal/helpers/classes.py", line 361, in __call__ table._db(table._id == id, ignore_common_filters=True).update(**newfields) File "/home/halal/.virtualenvs/venv/lib/python3.7/site-packages/pydal/objects.py", line 2699, in update ret = db._adapter.update(table, self.query, row.op_values()) File "/home/halal/.virtualenvs/venv/lib/python3.7/site-packages/pydal/adapters/base.py", line 586, in update raise e File "/home/halal/.virtualenvs/venv/lib/python3.7/site-packages/pydal/adapters/base.py", line 581, in update self.execute(sql) File "/home/halal/.virtualenvs/venv/lib/python3.7/site-packages/pydal/adapters/__init__.py", line 69, in wrap return f(*args, **kwargs) File "/home/halal/.virtualenvs/venv/lib/python3.7/site-packages/pydal/adapters/base.py", line 468, in execute rv = self.cursor.execute(command, *args[1:], **kwargs) sqlite3.OperationalError: database is locked

Val K

unread,
Oct 30, 2020, 7:00:16 AM10/30/20
to py4web
  check for  `db.commit()` in your models files and controllers - py4web does not call it automatically  

пятница, 30 октября 2020 г. в 12:49:03 UTC+3, ibraheema...@gmail.com:

Abdoul salam

unread,
Oct 30, 2020, 8:37:40 AM10/30/20
to py4web
Thanks. It helps. now i have this.smtperror.PNG

Nico Zanferrari

unread,
Nov 4, 2020, 9:57:32 AM11/4/20
to py4web
Hi,

I've tested it with a free PA account that uses python 3.8.0 by default, and this works fine from the Bash [note that you have to start py4web in the background in order to be able to use the same console, i.e : py4web run apps --port 8001  & > apps.log]

But, as I've expected, when you run the same app inside py4web as a web application within the PA framework, it does not work. Specifically: 


Massimo DiPierro

unread,
Nov 4, 2020, 10:55:04 AM11/4/20
to Nico Zanferrari, py4web
As an experiment. Can you try comment monkey.patch_all() ?

Nico Zanferrari

unread,
Nov 4, 2020, 11:06:40 AM11/4/20
to Massimo DiPierro, py4web
I've just tried by commenting the line in core.py (   #gevent.monkey.patch_all()). 

Now:


Maybe I should try an update to the latest version, this is "1.20200911.2"

Nico

Val K

unread,
Nov 5, 2020, 4:59:19 PM11/5/20
to py4web
It seems that it is uWSGI issue (I suppose It also patches something), 
I moved monkey.patch_all to the PA-wsgi-script  (as "Patching should be done as early as possible" - see http://www.gevent.org/api/gevent.monkey.html)
but it doesnt solve the problem - requests doesnt work.
But if I just run python from bash console and do this:
from gevent import monkey
monkey.patch_all()
import requests 
requests.get('https://google.com')  
- that works fine 
Also, I tested requests on my server nginx+gunicorn  - works fine (with monkey.patch_all() )


среда, 4 ноября 2020 г. в 19:06:40 UTC+3, nico...@gmail.com:

Massimo

unread,
Nov 29, 2020, 5:58:03 PM11/29/20
to py4web
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.

Can you please confirm this works for you? Thoughts?

I am not sure this is the best solutions. The reason gevent is there is that I was planning to add websockets support and they works better with gevent than Tornado in my experience. Yet we are not using any async feature at this time.

Massimo

Val K

unread,
Nov 29, 2020, 7:42:00 PM11/29/20
to py4web
We can just set some os/wsgi env variable at PA starting script ( or use some existing  to detect that it is uwsgi/PA) before import py4web and then check it in core.py before patching

понедельник, 30 ноября 2020 г. в 01:58:03 UTC+3, Massimo:

Nico Zanferrari

unread,
Dec 2, 2020, 1:06:43 PM12/2/20
to Massimo, py4web
Hi Massimo,

I do confirm that with the latest version (with the gevent removal) the problem has been resolved. I'm sorry that I've previously reported that it was not working - maybe I'd forgotten to reload the web app....
Anyhow, this is working fine now, and I can also report that the SMTP problem has gone, too, even with the free account ;-) I'm adding a note to Issue #288.

As a little side effect of gevent removal is on Windows, where the Ctrl-C key sequence does not work anymore to stop the bottle web server: you need to send Ctrl-Break. But this is just annoying.


Thanks a lot,
Nico

Massimo

unread,
Dec 6, 2020, 9:05:22 PM12/6/20
to py4web
yes. it is annoying. Have any idea how to resolve it?

Massimo

unread,
Dec 12, 2020, 1:55:57 PM12/12/20
to py4web
To be clear. It works fine without gevent and currently py4web is not using gevent.
Reply all
Reply to author
Forward
0 new messages