py4web in Google App Engine route app

311 views
Skip to first unread message

Jacinto Parga

unread,
Feb 4, 2020, 1:46:32 PM2/4/20
to web2py-users
I cannot properly deploy a simple py4web app in GAE. I think it's just a .gcloudignore or a app.yaml configuration issue. The only thing I've got is a not found page.

minimal-py4web.png

Some help about how to route the right app in the google app engine?

Thanks



Christian Varas

unread,
Feb 4, 2020, 2:09:59 PM2/4/20
to web...@googlegroups.com
Hi I haven’t tried GAE but maybe is the controller.

Are you using the decorator ’action()’ to expose the function ?.

Ex:
@action('some_name')
def some_function():

  return locals()

Then you acces like http://IP/your_app/some_name

Cheers.
Chris.

--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to the Google Groups "web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to web2py+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/web2py/a7ba6f1c-2c53-4f30-8197-9c0b51d3229d%40googlegroups.com.

Jacinto Parga

unread,
Feb 5, 2020, 3:38:56 PM2/5/20
to web2py-users
No, thanks.

Finally it was a problem with the .gcloudignore

I had to get rid off every app but the one I wanted to deploy and the other unneccesary files to the GAE. The only thing left is that I need to add the name of the application to route the main domain to the proper app.

This is my .gcloudignore
# This file specifies files that are *not* uploaded to Google Cloud Platform
# using gcloud. It follows the same syntax as .gitignore, with the addition of
# "#!include" directives (which insert the entries of the given .gitignore-style
# file at that point).
#
# For more information, run:
#   $ gcloud topic gcloudignore
#
.gcloudignore
# If you would like to upload your .git directory, .gitignore file or files
# from your .gitignore file, remove the corresponding line
# below:
.git
.gitignore

#Ojo no se puede quitar requirements.txt

# Python pycache:
__pycache__/
# Ignored by the build system
/setup.cfg

.travis.yml
*.pyc
*.pyo
*~
#*
*.1
*.bak
*.bak2
*.svn
*.w2p
*.class
*.rej
*.orig
Thumbs.db
.DS_Store
./deposit
./benchmark
./build
./dist
./ssl
./docs
./logs
./*.zip
!apps/*
apps/filemanager
apps/filemanager/*
apps/todo
apps/todo/*
apps/examples
apps/examples/*
apps/_dashboard
apps/_dashboard/*
apps/_scaffold
apps/_scaffold/*
apps/_minimal
apps/_minimal/*
apps/_default
apps/_default/*
apps/_documentation/*
apps/superheroes
apps/superheroes/*
apps/*/databases/README*
pps/*/databases/*
apps/*/uploads/*
apps/*/*.py[oc]
packages/
deployment_tools/*
deployment_tools/
tests/*
tests/
README.md
test-requirements.txt
source-context.json
password.txt
py4web-start.py
setup.py


And I'm using the default app.yaml may be this is the problem

runtime: python37


# Handlers define how to route requests to your application.
handlers:

- url: .*  # This regex directs all routes to main.bottle
  script: auto

So I had to write  the name of the application in the navigation bar: 


In other case I get a not found page.

And it goes very very slow, it is only a login page.

Some help?



El martes, 4 de febrero de 2020, 20:09:59 (UTC+1), Christian Varas escribió:
Hi I haven’t tried GAE but maybe is the controller.

Are you using the decorator ’action()’ to expose the function ?.

Ex:
@action('some_name')
def some_function():

  return locals()

Then you acces like http://IP/your_app/some_name

Cheers.
Chris.
El El mar, 4 de feb. de 2020 a la(s) 15:46, Jacinto Parga <jpa...@gmail.com> escribió:
I cannot properly deploy a simple py4web app in GAE. I think it's just a .gcloudignore or a app.yaml configuration issue. The only thing I've got is a not found page.

minimal-py4web.png

Some help about how to route the right app in the google app engine?

Thanks




--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to the Google Groups "web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to web...@googlegroups.com.

Massimo Di Pierro

unread,
Feb 10, 2020, 1:07:02 AM2/10/20
to web2py-users
Your .gitcloudignore appears to be ignoring all of the apps:

apps/filemanager
apps/filemanager/*
apps/todo
apps/todo/*
apps/examples
apps/examples/*
apps/_dashboard
apps/_dashboard/*
apps/_scaffold
apps/_scaffold/*
apps/_minimal
apps/_minimal/*
apps/_default
apps/_default/*
apps/_documentation/*
apps/superheroes
apps/superheroes/*



Jacinto Parga

unread,
Mar 14, 2020, 8:39:22 AM3/14/20
to web2py-users
Yes. I've created a new application that is the only one I want to serve. In that case how can I  do in py4web the same thing I do with routes.py in web2py

Thanks

Jacinto Parga

unread,
Mar 16, 2020, 5:17:56 AM3/16/20
to web2py-users
Finally solved.
  1. I add an entrypoint to the app.yaml . The app runs fine:
    runtime: python37
    entrypoint: gunicorn -b :8080 -w 2 main:app 


  1. # Handlers define how to route requests to your application.
    handlers:

  1. - url: /.*
      secure: always
      redirect_http_response_code: 301
      script: auto

  2. I get rid off all the apps but the default app and the app I want to deploy in the .gcloudignore:
  1. # This file specifies files that are *not* uploaded to Google Cloud Platform
    # using gcloud. It follows the same syntax as .gitignore, with the addition of
    # "#!include" directives (which insert the entries of the given .gitignore-style
    # file at that point).
    #
    # For more information, run:
    #   $ gcloud topic gcloudignore
    #
    .gcloudignore
    # If you would like to upload your .git directory, .gitignore file or files
    # from your .gitignore file, remove the corresponding line
    # below:
    .git
    .gitignore

  1. # Only ignore the default app and the app we want to deploy
    env/*
    env/
    !apps/*
  1. apps/todo
    apps/todo/*
    apps/examples
    apps/examples/*
    apps/_dashboard
    apps/_dashboard/*
    apps/_scaffold
    apps/_scaffold/*
    apps/_minimal
    apps/_minimal/*
  1. !apps/_default
    !apps/_default/*
    !apps/myapp
    !apps/myapp/*
    apps/_documentation/*
    apps/superheroes
    apps/superheroes/*
    apps/myfeed
    apps/myfeed/*
  1. apps/*/databases/README*
    pps/*/databases/*
    apps/*/uploads/*
    apps/*/*.py[oc]
    packages/
    deployment_tools/*
    deployment_tools/
    tests/*
    tests/
    README.md
    test-requirements.txt
    source-context.json
    password.txt
    py4web-start.py
    setup.py
  1. Makefile
    So when it is deployed in GAE http://myapp.appspot.com/ goes to _default/index.html url
  2. I modify the __init.py__ file of the _default app to redirect to myapp folder:
    from py4web import action, __version__
    from bottle import redirect  #get redirect function from bottle

    @action("index")
    @action.uses("index.html")
    def index():
          redirect("/myapp")  # The former code: return dict(version=__version__)
    The result is that http://myapp.appspot.com/ serves http://myapp.app.com/myapp
Maybe there is a more elegant way to get it. Any suggestion would be appreciated.

Thanks

Massimo Di Pierro

unread,
Mar 21, 2020, 3:03:00 AM3/21/20
to web2py-users
This is a good solution. One trick is to symlink _default to myapp

Jacinto Parga

unread,
Mar 23, 2020, 8:01:41 AM3/23/20
to web2py-users
Yes, but I get an error with symlink in __init.py__ of _default: 

from py4web import action, __version__
import os

@action("index")
@action.uses("index.html")
def index():
    src = "/_default"
    dst = "/myapp"
    os.symlink(src, dst)
    return dict(version=__version__)


Error Ticket: [Errno 13] Permission denied: '/_default' -> '/myapp'

Traceback (most recent call last):
  File "/home/jacinto/PROGRAMACION/py4web/py4web/core.py", line 554, in wrapper
    ret = func(*func_args, **func_kwargs)
  File "/home/jacinto/PROGRAMACION/py4web/py4web/core.py", line 515, in wrapper
    ret = func(*args, **kwargs)
  File "apps/_default/__init__.py", line 10, in index
    os.symlink(src, dst)
PermissionError: [Errno 13] Permission denied: '/_default' -> '/myapp'

id48
uuid8b97b87a-7ec0-4158-bace-e414438f513a
app_name_default
methodGET
path/
timestampdatetime.datetime(2020, 3, 23, 11, 48, 18)
client_ip127.0.0.1
error[Errno 13] Permission denied: '/_default' -> '/myapp'
snapshot
timestamp2020-03-23T11:48:18.745672
python_version3.7.5 (default, Nov 20 2019, 09:21:52) 

Massimo Di Pierro

unread,
Mar 24, 2020, 12:17:40 AM3/24/20
to web2py-users
There are two problems here:
1) you cannot symlink in an action because it must be done once and only once.
2) You cannot have paths like /_default because they are absolute paths

Assuming this is a linux or OSX machine you should do from the shell

$ rm -rf apps/_default
$ ln -s apps/myapp apps/_default

You only need to do this once.

Jacinto Parga

unread,
Apr 9, 2020, 4:34:58 PM4/9/20
to web2py-users
Thanks, perfect!! It's better.

I have some apps deployed in GAE, with web2py pyhton 2.7. I want to migrate them to python 3.7, but cannot deploy web2py python 3.7 on GAE. I wonder if stable version of py4web will take too long or if it is better to try to find out how to deploy web2py python 3.7 on GAE
Reply all
Reply to author
Forward
0 new messages