I'm trying to get a Python Google App Engine to run locally (macOS Sierra) and am having all sorts of trouble with and was wondering what I could possibly be missing. Please note this is my first foray into Python (usually develop with Ruby).
I've downloaded Google App Engine sdk for python and followed the steps to get it up and running. After a few attempts I've placed it within the same directory as my App.
I'm using Python 2.7.x which is what the App requires.
I'm using virtualenv so I've initiated it like so: source bin/activate and try to run the app like so: dev_appserver.py --storage_path=../GAE-storage/ --port=9080 --log_level=info $* .
When I try ti visit the page I get an error like:
Traceback (most recent call last):
File "/Users/wm/lib/google-cloud-sdk/platform/google_appengine/google/appengine/runtime/wsgi.py", line 240, in Handle
handler = _config_handle.add_wsgi_middleware(self._LoadHandler())
File "/Users/wm/lib/google-cloud-sdk/platform/google_appengine/google/appengine/api/lib_config.py", line 354, in __getattr__
self._update_configs()
File "/Users/wm/lib/google-cloud-sdk/platform/google_appengine/google/appengine/api/lib_config.py", line 290, in _update_configs
self._registry.initialize()
File "/Users/wm/lib/google-cloud-sdk/platform/google_appengine/google/appengine/api/lib_config.py", line 165, in initialize
import_func(self._modname)
File "/Library/WebServer/Documents/python/flow.city/appengine_config.py", line 19, in <module>
from django.conf import settings
ImportError: No module named django.conf
INFO 2016-11-20 11:09:47,599 module.py:788] default: "GET / HTTP/1.1" 500 -
So, to fix this issue I've downloaded Django manually and extracted it to app directory. Then it complained I don't features, so I've also downloaded it manually and added to the project directory. Now is complaining about something else:
ERROR 2016-11-20 11:29:18,635 wsgi.py:263]
Traceback (most recent call last):
File "/Users/wm/lib/google-cloud-sdk/platform/google_appengine/google/appengine/runtime/wsgi.py", line 240, in Handle
handler = _config_handle.add_wsgi_middleware(self._LoadHandler())
File "/Users/wm/lib/google-cloud-sdk/platform/google_appengine/google/appengine/api/lib_config.py", line 354, in __getattr__
self._update_configs()
File "/Users/wm/lib/google-cloud-sdk/platform/google_appengine/google/appengine/api/lib_config.py", line 290, in _update_configs
self._registry.initialize()
File "/Users/wm/lib/google-cloud-sdk/platform/google_appengine/google/appengine/api/lib_config.py", line 165, in initialize
import_func(self._modname)
File "/Library/WebServer/Documents/python/flow.city/appengine_config.py", line 22, in <module>
import features
File "/Library/WebServer/Documents/python/flow.city/flowcity/features.py", line 23, in <module>
from base.basics import get_config
File "/Library/WebServer/Documents/python/flow.city/flowcity/base/basics.py", line 13, in <module>
from dbutils import date_to_str, rescale, get_app_url
File "/Library/WebServer/Documents/python/flow.city/flowcity/dbutils.py", line 23, in <module>
from i18n import _
File "/Library/WebServer/Documents/python/flow.city/flowcity/i18n.py", line 12, in <module>
from django.utils.translation import *
TypeError: Item in ``from list'' not a string
INFO 2016-11-20 11:29:18,641 module.py:788] default: "GET / HTTP/1.1" 500 -
So it makes me wonder if the approach I've taken is the right approach to get the App running locally? When cloning a new project in Ruby, I'd do a bundle install so it'd download all requirements for that project. Is there something similar in Python that I should do?
Please note that I've also tried without virtualenv and results were the same.
Related
Went to go work on an older Python2.7 AppEngine Standard project today but I can't seem to get Endpoints to work. I downloaded the sample code to see if my project was the culprit, but the sample doesn't work either. https://cloud.google.com/endpoints/docs/frameworks/python/get-started-frameworks-python#run_local
dev_appserver.py --host 192.168.1.73 app.yaml --smtp_host=smtp.telus.net --smtp_port=25
INFO 2020-02-04 19:46:38,243 devappserver2.py:289] Skipping SDK update check.
INFO 2020-02-04 19:46:38,303 api_server.py:282] Starting API server at: http://localhost:45473
INFO 2020-02-04 19:46:38,325 dispatcher.py:267] Starting module "default" running at: http://192.168.1.73:8080
INFO 2020-02-04 19:46:38,326 admin_server.py:150] Starting admin server at: http://localhost:8000
Everything starts Okay, but when I hit the Endpoint: /_ah/api/echo/v1/echo
Traceback (most recent call last):
File "/usr/lib/google-cloud-sdk/platform/google_appengine/google/appengine/runtime/wsgi.py", line 240, in Handle
handler = _config_handle.add_wsgi_middleware(self._LoadHandler())
File "/usr/lib/google-cloud-sdk/platform/google_appengine/google/appengine/runtime/wsgi.py", line 311, in _LoadHandler
handler, path, err = LoadObject(self._handler)
File "/usr/lib/google-cloud-sdk/platform/google_appengine/google/appengine/runtime/wsgi.py", line 85, in LoadObject
obj = __import__(path[0])
File "/home/mparkes/app_engine_projects/samples/python-docs-samples/appengine/standard/endpoints-frameworks-v2/echo/main.py", line 19, in <module>
import endpoints
File "/home/mparkes/app_engine_projects/samples/python-docs-samples/appengine/standard/endpoints-frameworks-v2/echo/lib/endpoints/__init__.py", line 33, in <module>
from .apiserving import *
File "/home/mparkes/app_engine_projects/samples/python-docs-samples/appengine/standard/endpoints-frameworks-v2/echo/lib/endpoints/apiserving.py", line 71, in <module>
from endpoints_management.control import client as control_client
File "/home/mparkes/app_engine_projects/samples/python-docs-samples/appengine/standard/endpoints-frameworks-v2/echo/lib/endpoints_management/__init__.py", line 19, in <module>
from . import auth, config, control, gen
File "/home/mparkes/app_engine_projects/samples/python-docs-samples/appengine/standard/endpoints-frameworks-v2/echo/lib/endpoints_management/config/__init__.py", line 17, in <module>
from .service_config import ServiceConfigException
File "/home/mparkes/app_engine_projects/samples/python-docs-samples/appengine/standard/endpoints-frameworks-v2/echo/lib/endpoints_management/config/service_config.py", line 25, in <module>
from apitools.base.py import encoding
File "/home/mparkes/app_engine_projects/samples/python-docs-samples/appengine/standard/endpoints-frameworks-v2/echo/lib/apitools/base/py/__init__.py", line 23, in <module>
from apitools.base.py.credentials_lib import *
File "/home/mparkes/app_engine_projects/samples/python-docs-samples/appengine/standard/endpoints-frameworks-v2/echo/lib/apitools/base/py/credentials_lib.py", line 44, in <module>
import fasteners
File "/home/mparkes/app_engine_projects/samples/python-docs-samples/appengine/standard/endpoints-frameworks-v2/echo/lib/fasteners/__init__.py", line 23, in <module>
from fasteners.lock import locked # noqa
File "/home/mparkes/app_engine_projects/samples/python-docs-samples/appengine/standard/endpoints-frameworks-v2/echo/lib/fasteners/lock.py", line 24, in <module>
from fasteners import _utils
File "/home/mparkes/app_engine_projects/samples/python-docs-samples/appengine/standard/endpoints-frameworks-v2/echo/lib/fasteners/_utils.py", line 39, in <module>
from monotonic import monotonic as now # noqa
File "/home/mparkes/app_engine_projects/samples/python-docs-samples/appengine/standard/endpoints-frameworks-v2/echo/lib/monotonic.py", line 169, in <module>
raise RuntimeError('no suitable implementation for this system: ' + repr(e))
INFO 2020-02-04 19:46:45,501 module.py:865] default: "GET /_ah/api/static/proxy.html?usegapi=1&jsh=m%3B%2F_%2Fscs%2Fapps-static%2F_%2Fjs%2Fk%3Doz.gapi.en.xh-S9KbEGSE.O%2Fam%3DwQc%2Fd%3D1%2Fct%3Dzgms%2Frs%3DAGLTcCNaUSRWzhd71dAsiMVOstVE3KcJZw%2Fm%3D__features__ HTTP/1.1" 500 -
RuntimeError: no suitable implementation for this system: IOError(13, 'file not accessible')
Does this have something to do with python2.7 support being dropped on Jan 1 2020? For the record my app still runs fine on Appengine, but I wont be able to do anymore development.
[EDIT] Google Cloud Version:
Google Cloud SDK 279.0.0
alpha 2020.01.31
app-engine-python 1.9.88
app-engine-python-extras 1.9.88
[EDIT] Python:
Python 2.7.17 (default, Nov 7 2019, 10:07:09)
[GCC 7.4.0] on linux2
If I migrate to Python 3, then I lose endpoints and I'll need to completely rewrite my client code.
Thanks in advance.
I was able to get this to work using an older version of the SDK I had.
google_appengine_1.6.63
Did the trick. I guess the newest version Google Cloud SDK 279.0.0 & app-engine-python 1.9.88 I was using has a problem with dev_appserver.py
[EDIT] Also to note the following version works too
google_appengine_1.9.87
seemes to be a problem with 1.9.88
Hope this helps anyone having the same problem.
I have downloaded the appengine samples.
When I enter directory python-docs-samples/appengine/standard/django and install it on my appengine project, and then look at the project web page, I get this error:
Traceback (most recent call last):
File "/base/alloc/tmpfs/dynamic_runtimes/python27/b93f87cfaa0115e5_unzipped/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 240, in Handle
handler = _config_handle.add_wsgi_middleware(self._LoadHandler())
File "/base/alloc/tmpfs/dynamic_runtimes/python27/b93f87cfaa0115e5_unzipped/python27_lib/versions/1/google/appengine/api/lib_config.py", line 358, in __getattr__
self._update_configs()
File "/base/alloc/tmpfs/dynamic_runtimes/python27/b93f87cfaa0115e5_unzipped/python27_lib/versions/1/google/appengine/api/lib_config.py", line 294, in _update_configs
self._registry.initialize()
File "/base/alloc/tmpfs/dynamic_runtimes/python27/b93f87cfaa0115e5_unzipped/python27_lib/versions/1/google/appengine/api/lib_config.py", line 165, in initialize
import_func(self._modname)
File "/base/alloc/tmpfs/dynamic_runtimes/python27/b93f87cfaa0115e5_unzipped/python27_dist/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/base/data/home/apps/s~forcediagnosticsclinic/20180707t052537.410964682053028174/appengine_config.py", line 18, in <module>
vendor.add('lib')
File "/base/alloc/tmpfs/dynamic_runtimes/python27/b93f87cfaa0115e5_unzipped/python27_lib/versions/1/google/appengine/ext/vendor/__init__.py", line 44, in add
'No such virtualenv or site directory' % path)
ValueError: virtualenv: cannot access lib: No such virtualenv or site directory
What is going on?
You app config refers to folder called lib and this folder is missing or you forgot to copy it properly. Try to get the same project working on your local computer.
Lenik is right. Specifically, it looks like you didn't do this step in the tutorial:
pip install -r requirements-vendor.txt -t lib/
https://cloud.google.com/python/django/appengine#run_the_app_on_your_local_computer
I am following the google cloud intro for python apps.
I am using a simple flask app similar to the example in the page with the addition of using the psycopg2 python library for postgres.
When run under the google SDK dev_appserver.py script, the stack below is thrown. I believe that what is happening is that the dev_appserver.py script is acting as a sandbox and not allowing the native code aspects of psycopg2 to be imported - presumably as native code is not allowed on the google python app infra (_psycopg2.pyd is in the psycopg2 install)
What I do not understand however is that postgres is in beta for google cloud SQL and a similar guide from Google indicates that psycopg2 is supported.
But I'm getting the following error:
ERROR 2018-02-20 02:55:51,746 wsgi.py:263]
Traceback (most recent call last):
File "C:\Users\grant\AppData\Local\Google\Cloud SDK\google-cloud-sdk\platform\google_appengine\google\appengine\runtime\wsgi.py", line 240, in Handle
handler = _config_handle.add_wsgi_middleware(self._LoadHandler())
File "C:\Users\grant\AppData\Local\Google\Cloud SDK\google-cloud-sdk\platform\google_appengine\google\appengine\runtime\wsgi.py", line 299, in _LoadHandler
handler, path, err = LoadObject(self._handler)
File "C:\Users\grant\AppData\Local\Google\Cloud SDK\google-cloud-sdk\platform\google_appengine\google\appengine\runtime\wsgi.py", line 85, in LoadObject
obj = __import__(path[0])
File "C:\Users\grant\PycharmProjects\graph\google_app.py", line 2, in <module>
from db.store import Store
File "C:\Users\grant\PycharmProjects\graph\db\store.py", line 2, in <module>
from db.objects import Objects
File "C:\Users\grant\PycharmProjects\graph\db\objects.py", line 5, in <module>
from psycopg2.extras import execute_values
File "C:\Users\grant\PycharmProjects\graph\3rd\psycopg2\__init__.py", line 50, in <module>
from psycopg2._psycopg import ( # noqa
File "C:\Users\grant\AppData\Local\Google\Cloud SDK\google-cloud-sdk\platform\google_appengine\google\appengine\tools\devappserver2\python\runtime\sandbox.py", line 1093, in load_module
raise ImportError('No module named %s' % fullname)
ImportError: No module named psycopg2._psycopg
INFO 2018-02-19 21:55:51,757 module.py:835] default: "GET /gui HTTP/1.1" 500 -
I have an App Engine application which breaks the moment I do
import apache_beam
I can confirm the dependencies are installed within the virtual environment the app runs in. Judging by the stack trace below it looks like it's trying to access /dev/null for some reason and it fails to.
INFO 2017-08-13 13:03:37,980 stubs.py:50] Sandbox prevented access to file "/home/raul/Downloads/google-cloud-sdk"
INFO 2017-08-13 13:03:37,980 stubs.py:51] If it is a static file, check that `application_readable: true` is set in your app.yaml
INFO 2017-08-13 13:03:37,980 stubs.py:50] Sandbox prevented access to file "/home/raul/Downloads/google-cloud-sdk/platform"
INFO 2017-08-13 13:03:37,980 stubs.py:51] If it is a static file, check that `application_readable: true` is set in your app.yaml
INFO 2017-08-13 13:03:38,260 stubs.py:50] Sandbox prevented access to file "/dev/null"
INFO 2017-08-13 13:03:38,260 stubs.py:51] If it is a static file, check that `application_readable: true` is set in your app.yaml
ERROR 2017-08-13 13:03:38,261 wsgi.py:263]
Traceback (most recent call last):
File "/home/raul/Downloads/google-cloud-sdk/platform/google_appengine/google/appengine/runtime/wsgi.py", line 240, in Handle
handler = _config_handle.add_wsgi_middleware(self._LoadHandler())
File "/home/raul/Downloads/google-cloud-sdk/platform/google_appengine/google/appengine/runtime/wsgi.py", line 299, in _LoadHandler
handler, path, err = LoadObject(self._handler)
File "/home/raul/Downloads/google-cloud-sdk/platform/google_appengine/google/appengine/runtime/wsgi.py", line 85, in LoadObject
obj = __import__(path[0])
File "/home/raul/Documents/football/main.py", line 7, in <module>
import apache_beam
File "/home/raul/Documents/football/env/lib/python2.7/site-packages/apache_beam/__init__.py", line 75, in <module>
import apache_beam.internal.pickler
File "/home/raul/Documents/football/env/lib/python2.7/site-packages/apache_beam/internal/pickler.py", line 38, in <module>
import dill
File "/home/raul/Documents/football/env/lib/python2.7/site-packages/dill/__init__.py", line 27, in <module>
from .dill import dump, dumps, load, loads, dump_session, load_session, \
File "/home/raul/Documents/football/env/lib/python2.7/site-packages/dill/dill.py", line 165, in <module>
FileType = type(open(os.devnull, 'rb', buffering=0))
File "/home/raul/Downloads/google-cloud-sdk/platform/google_appengine/google/appengine/tools/devappserver2/python/stubs.py", line 260, in __init__
raise IOError(errno.EACCES, 'file not accessible', filename)
IOError: [Errno 13] file not accessible: '/dev/null'
Any ideas what might be causing this and how to fix it?
The GAE Python sandbox is pretty restrictive in terms of what your app code is allowed to do. It looks like the dill package used by apache-beam needs to access special files (the /dev/null device file in this case) which is not allowed on the sandbox.
You either change your code to meet all sandbox requirements or try to use the flexible environment, which is a lot more tolerant (but it's a different beast overall). See Choosing an App Engine Environment and Migrating Services from the Standard Environment to the Flexible Environment.
Side note: the traceback indicates your app tried to execute apache-beam from the local system installation, which also won't work in the standard environment - it needs to be vendored into your application, see Installing a third-party library.
I'm trying to learn Python and figured I'd build an app to host on GAE because it's free.
I'm following this guide here: http://code.google.com/appengine/docs/python/gettingstartedpython27/helloworld.html
and have the exact files: helloworld.py and app.yaml inside my helloworld directory but when I launch it I get this error:
Traceback (most recent call last):
File "C:\Program Files\Google\google_appengine\google\appengine\runtime\wsgi.py", line 187, in Handle
handler = _config_handle.add_wsgi_middleware(self._LoadHandler())
File "C:\Program Files\Google\google_appengine\google\appengine\runtime\wsgi.py", line 225, in _LoadHandler
handler = __import__(path[0])
ImportError: No module named helloworld
INFO 2012-03-21 19:36:47,219 dev_appserver.py:2865] "GET / HTTP/1.1" 500 -
Python is still greek to me and it's no fun struggling with environment configuration when you're new to something. What did I do wrong? Does it matter than I have GAE/J installed?