I'm trying to set up a Web.py (0.37) project in a virtualenv to run on Google App Engine (1.7.2) but I'm getting a ImportError: No module named web from the appserver.
I've installed web.py using python setup.py install from inside my virtualenv and can confirm that it's installed properly because I can import it from the python interpreter.
My actual GAE folder is outside the virtualenv but linked like so:
ln -s ~/Development/google_appengine $VIRTUAL_ENV/google_appengine
and added to my python path in $VIRTUAL_ENV/lib/python2.7/site-packages/gae.pth
There must be an extra step I'm missing, heres the error message:
ERROR 2012-10-03 09:03:17,442 wsgi.py:203]
Traceback (most recent call last):
File "/home/sett/Development/google_appengine/google/appengine/runtime/wsgi.py", line 195, in Handle
handler = _config_handle.add_wsgi_middleware(self._LoadHandler())
File "/home/sett/Development/google_appengine/google/appengine/runtime/wsgi.py", line 239, in _LoadHandler
handler = __import__(path[0])
File "/home/sett/Development/google_appengine/google/appengine/tools/dev_appserver_import_hook.py", line 719, in Decorate
return func(self, *args, **kwargs)
File "/home/sett/Development/google_appengine/google/appengine/tools/dev_appserver_import_hook.py", line 1923, in load_module
return self.FindAndLoadModule(submodule, fullname, search_path)
File "/home/sett/Development/google_appengine/google/appengine/tools/dev_appserver_import_hook.py", line 719, in Decorate
return func(self, *args, **kwargs)
File "/home/sett/Development/google_appengine/google/appengine/tools/dev_appserver_import_hook.py", line 1787, in FindAndLoadModule
description)
File "/home/sett/Development/google_appengine/google/appengine/tools/dev_appserver_import_hook.py", line 719, in Decorate
return func(self, *args, **kwargs)
File "/home/sett/Development/google_appengine/google/appengine/tools/dev_appserver_import_hook.py", line 1730, in LoadModuleRestricted
description)
File "/home/sett/wip/rigmarolesoup/main.py", line 1, in <module>
import web
ImportError: No module named web
App engine won't let you import 3rd party modules from site-packages; you must copy web.py into your app directory.
Related
I'm getting following error when I try to run the tcms-api module but following the steps given,
https://tcms-api.readthedocs.io/en/latest/modules/tcms_api.html#module-tcms_api
I'm using python 3 in CentOS, applied our own domain and certificates by mounting the certificates to docker container.
Can you please tell how to solve the SSL Certificate verification failure error?
[root#KiwiTCMS-Testcase-Portal docker-compose]# python3 test-api.py
Traceback (most recent call last):
File "test-api.py", line 5, in <module>
rpc_client = TCMS()
File "/opt/rh/rh-python36/root/usr/lib/python3.6/site-packages/tcms_api/__init__.py", line 123, in __init__
config['tcms']['url']).server
File "/opt/rh/rh-python36/root/usr/lib/python3.6/site-packages/tcms_api/xmlrpc.py", line 124, in __init__
self.login(username, password, url)
File "/opt/rh/rh-python36/root/usr/lib/python3.6/site-packages/tcms_api/xmlrpc.py", line 131, in login
self.server.Auth.login(username, password)
File "/opt/rh/rh-python36/root/usr/lib64/python3.6/xmlrpc/client.py", line 1112, in __call__
return self.__send(self.__name, args)
File "/opt/rh/rh-python36/root/usr/lib64/python3.6/xmlrpc/client.py", line 1452, in __request
verbose=self.__verbose
File "/opt/rh/rh-python36/root/usr/lib64/python3.6/xmlrpc/client.py", line 1154, in request
return self.single_request(host, handler, request_body, verbose)
File "/opt/rh/rh-python36/root/usr/lib64/python3.6/xmlrpc/client.py", line 1166, in single_request
http_conn = self.send_request(host, handler, request_body, verbose)
File "/opt/rh/rh-python36/root/usr/lib64/python3.6/xmlrpc/client.py", line 1279, in send_request
self.send_content(connection, request_body)
File "/opt/rh/rh-python36/root/usr/lib64/python3.6/xmlrpc/client.py", line 1309, in send_content
connection.endheaders(request_body)
File "/opt/rh/rh-python36/root/usr/lib64/python3.6/http/client.py", line 1282, in endheaders
self._send_output(message_body, encode_chunked=encode_chunked)
File "/opt/rh/rh-python36/root/usr/lib64/python3.6/http/client.py", line 1042, in _send_output
self.send(msg)
File "/opt/rh/rh-python36/root/usr/lib64/python3.6/http/client.py", line 980, in send
self.connect()
File "/opt/rh/rh-python36/root/usr/lib64/python3.6/http/client.py", line 1448, in connect
server_hostname=server_hostname)
File "/opt/rh/rh-python36/root/usr/lib64/python3.6/ssl.py", line 407, in wrap_socket
_context=self, _session=session)
File "/opt/rh/rh-python36/root/usr/lib64/python3.6/ssl.py", line 817, in __init__
self.do_handshake()
File "/opt/rh/rh-python36/root/usr/lib64/python3.6/ssl.py", line 1077, in do_handshake
self._sslobj.do_handshake()
File "/opt/rh/rh-python36/root/usr/lib64/python3.6/ssl.py", line 689, in do_handshake
self._sslobj.do_handshake()
ssl.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:852)
Introducing the following line fix the issue,
import ssl
try:
_create_unverified_https_context = ssl._create_unverified_context
except AttributeError:
# Legacy Python that doesn't verify HTTPS certificates by default
pass
else:
# Handle target environment that doesn't support HTTPS verification
ssl._create_default_https_context = _create_unverified_https_context
I see that you are using Python 3.6 from RedHat's SoftwareCollections. That version contains a bug (or arguably a security feature) which doesn't respect settings documented in upstream Python which allow you to accept untrusted SSL certificates. There are lots of these things reported on bugzilla.redhat.com but I don't think they will change it!
This is how we do it in our test suite:
https://github.com/kiwitcms/tcms-api/blob/master/tests/krb5/integration_test.py#L18
I try to download my code from google using:
appcfg.py download_app -A "canada-math" ./trunk3
I have the old appengine installed under my home dir, which you can see in the error output below.
appcfg.py download_app -A "canada-math" ./trunk3
I get this:
stephen#stephen-AO725:~/webprog$ appcfg.py download_app -A "canada-math" ./trunk3
05:06 PM Host: appengine.google.com
05:06 PM Fetching file list...
Traceback (most recent call last):
File "/home/stephen/webprog/google_appengine/appcfg.py", line 171, in <module>
run_file(__file__, globals())
File "/home/stephen/webprog/google_appengine/appcfg.py", line 167, in run_file
execfile(script_path, globals_)
File "/home/stephen/webprog/google_appengine/google/appengine/tools/appcfg.py", line 4282, in <module>
main(sys.argv)
File "/home/stephen/webprog/google_appengine/google/appengine/tools/appcfg.py", line 4273, in main
result = AppCfgApp(argv).Run()
File "/home/stephen/webprog/google_appengine/google/appengine/tools/appcfg.py", line 2409, in Run
self.action(self)
File "/home/stephen/webprog/google_appengine/google/appengine/tools/appcfg.py", line 4003, in __call__
return method()
File "/home/stephen/webprog/google_appengine/google/appengine/tools/appcfg.py", line 2861, in DownloadApp
DoDownloadApp(rpcserver, out_dir, app_id, module, app_version)
File "/home/stephen/webprog/google_appengine/google/appengine/tools/appcfg.py", line 1373, in DoDownloadApp
result = rpcserver.Send('/api/files/list', **url_args)
File "/home/stephen/webprog/google_appengine/google/appengine/tools/appengine_rpc.py", line 393, in Send
f = self.opener.open(req)
File "/usr/lib/python2.7/urllib2.py", line 429, in open
response = self._open(req, data)
File "/usr/lib/python2.7/urllib2.py", line 447, in _open
'_open', req)
File "/usr/lib/python2.7/urllib2.py", line 407, in _call_chain
result = func(*args)
File "/usr/lib/python2.7/urllib2.py", line 1241, in https_open
context=self._context)
TypeError: do_open() got an unexpected keyword argument 'context'
The simplest fix is likely to download the source code by running appcfg.py in Cloud Shell. That will ensure that your appcfg.py and Python versions are compatible with the App Engine API.
Depending on your specific versions of appcfg and Python, you may have a version mismatch. Also keep in mind that appcfg is deprecated. See also:
SDK is incompatible with python 2.7.9
Deploying Google app engine with python failed
I did a gcloud components update 2 days ago and started getting this error when i run dev_appserver.py
(venv) myusername#mymachine:~/projects/myproject$ dev_appserver.py ./ --host 0.0.0.0 --port 8002 --enable_console --env_var GCS_TOKEN=ya29........YJDQAnp772B0
INFO 2019-03-13 23:45:31,205 devappserver2.py:278] Skipping SDK update check.
INFO 2019-03-13 23:45:31,268 api_server.py:275] Starting API server at: http://localhost:64587
INFO 2019-03-13 23:45:31,319 dispatcher.py:256] Starting module "default" running at: http://0.0.0.0:8002
INFO 2019-03-13 23:45:31,325 admin_server.py:150] Starting admin server at: http://localhost:8000
/usr/local/Caskroom/google-cloud-sdk/latest/google-cloud-sdk/platform/google_appengine/google/appengine/tools/devappserver2/mtime_file_watcher.py:182: UserWarning: There are too many files in your application for changes in all of them to be monitored. You may have to restart the development server to see some changes to your files.
'There are too many files in your application for '
INFO 2019-03-13 23:45:35,237 instance.py:294] Instance PID: 29760
appengine_config
requests.__version__ 2.21.0
Appengine config done
4
ERROR 2019-03-13 23:45:35,986 wsgi.py:263]
Traceback (most recent call last):
File "/usr/local/Caskroom/google-cloud-sdk/latest/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/local/Caskroom/google-cloud-sdk/latest/google-cloud-sdk/platform/google_appengine/google/appengine/runtime/wsgi.py", line 299, in _LoadHandler
handler, path, err = LoadObject(self._handler)
File "/usr/local/Caskroom/google-cloud-sdk/latest/google-cloud-sdk/platform/google_appengine/google/appengine/runtime/wsgi.py", line 85, in LoadObject
obj = __import__(path[0])
File "/Users/myusername/projects/myproject/main.py", line 34, in <module>
from bp_includes.lib.error_handler import handle_error
File "/Users/myusername/projects/myproject/bp_includes/lib/error_handler.py", line 15, in <module>
from bp_includes.lib import jinja_bootstrap
File "/Users/myusername/projects/myproject/bp_includes/lib/jinja_bootstrap.py", line 7, in <module>
from src.handlers.utils import ordinal
File "/Users/myusername/projects/myproject/src/handlers/utils.py", line 14, in <module>
from lib.pytz.gae import pytz
File "/Users/myusername/projects/myproject/lib/pytz/__init__.py", line 29, in <module>
from pkg_resources import resource_stream
File "/Users/myusername/projects/myproject/lib/pkg_resources/__init__.py", line 1022, in <module>
class Environment(object):
File "/Users/myusername/projects/myproject/lib/pkg_resources/__init__.py", line 1025, in Environment
def __init__(self, search_path=None, platform=get_supported_platform(),
File "/Users/myusername/projects/myproject/lib/pkg_resources/__init__.py", line 263, in get_supported_platform
plat = get_build_platform()
File "/Users/myusername/projects/myproject/lib/pkg_resources/__init__.py", line 472, in get_build_platform
INFO 2019-03-13 23:45:36,002 module.py:861] default: "GET /_ah/warmup HTTP/1.1" 500 -
version = _macosx_vers()
File "/Users/myusername/projects/myproject/lib/pkg_resources/__init__.py", line 439, in _macosx_vers
version = platform.mac_ver()[0]
File "/Users/myusername/projects/myproject/venv/lib/python2.7/platform.py", line 764, in mac_ver
info = _mac_ver_xml()
File "/Users/myusername/projects/myproject/venv/lib/python2.7/platform.py", line 741, in _mac_ver_xml
pl = plistlib.readPlist(fn)
File "/usr/local/Cellar/python#2/2.7.15_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plistlib.py", line 75, in readPlist
pathOrFile = open(pathOrFile)
File "/usr/local/Caskroom/google-cloud-sdk/latest/google-cloud-sdk/platform/google_appengine/google/appengine/tools/devappserver2/python/runtime/stubs.py", line 284, in __init__
raise IOError(errno.EACCES, 'file not accessible', filename)
IOError: [Errno 13] file not accessible: '/System/Library/CoreServices/SystemVersion.plist'
I originally installed gcloud with brew cask install google-cloud-sdk in case that's relevant
It looks like the problem was introduced in gcloud 238.0.0 probably with gcloud app Python Extensions 1.9.84. You can downgrade gcloud to lower version with:
gcloud components update --version 237.0.0
I got it to work by doing the following in appengine_config.py, but I'm hoping that someone has a better solution
try:
from google.appengine.tools.devappserver2.python.runtime.stubs import FakeFile
FakeFile._allowed_dirs.update(['/System/Library/CoreServices/'])
except ImportError:
pass
you can delete the lib folder where you requirements are installed and reinstall it worked for me
pip install -t "lib" -r requirements.txt
I am following this tutorial for user authentication on GAE, endpoints v2 in Python.
I use their code EXACTLY (only pasting in my app ID).
Running the code locally via PyCharm, it doesn't like the type of "issuers" wanting a dict: TypeError: issuers type doesn't match .
Has it something to do with IDE integration not being supported yet? What am I overlooking?
In full:
ERROR 2017-06-05 15:23:19,417 wsgi.py:263]
Traceback (most recent call last):
File "C:\Program Files (x86)\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:\Program Files (x86)\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:\Program Files (x86)\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(...)\web app\goal.py", line 103, in <module>
issuers=[firebase_issuer])
File "C:\Program Files (x86)\Google\Cloud SDK\google-cloud-sdk\platform\google_appengine\lib\protorpc-1.0\protorpc\util.py", line 173, in positional_wrapper
return wrapped(*args, **kwargs)
File "C:\Users\(...)\web app\lib\endpoints\api_config.py", line 976, in api
api_key_required=api_key_required, base_path=base_path)
File "C:\Program Files (x86)\Google\Cloud SDK\google-cloud-sdk\platform\google_appengine\lib\protorpc-1.0\protorpc\util.py", line 173, in positional_wrapper
return wrapped(*args, **kwargs)
File "C:\Users\(...)\web app\lib\endpoints\api_config.py", line 469, in __init__
base_path=base_path)
File "C:\Program Files (x86)\Google\Cloud SDK\google-cloud-sdk\platform\google_appengine\lib\protorpc-1.0\protorpc\util.py", line 173, in positional_wrapper
return wrapped(*args, **kwargs)
File "C:\Users\(...)\web app\lib\endpoints\api_config.py", line 550, in __init__
_CheckType(issuers, dict, 'issuers')
File "C:\Users\(...)\web app\lib\endpoints\api_config.py", line 195, in _CheckType
raise TypeError('%s type doesn\'t match %s.' % (name, check_type))
TypeError: issuers type doesn't match <type 'dict'>.
Apologies for the incorrect documentation. You do need to pass a dict. So try issuers={'firebase': firebase_issuer} instead.
A simple GAE application threw the following error on self.jinja2.render_template() on only one computer, but not on any others (both macs and pcs):
ERROR 2012-02-14 21:54:04,987 webapp2.py:1528] [Errno 13] file not accessible: 'templates/test.html'
Traceback (most recent call last):
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/webapp2/webapp2.py", line 1511, in __call__
rv = self.handle_exception(request, response, e)
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/webapp2/webapp2.py", line 1505, in __call__
rv = self.router.dispatch(request, response)
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/webapp2/webapp2.py", line 1253, in default_dispatcher
return route.handler_adapter(request, response)
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/webapp2/webapp2.py", line 1077, in __call__
return handler.dispatch()
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/webapp2/webapp2.py", line 547, in dispatch
return self.handle_exception(e, self.app.debug)
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/webapp2/webapp2.py", line 545, in dispatch
return method(*args, **kwargs)
File "/Users/scott/svn/GAE_branches/sample_broken_app/handlers.py", line 21, in get
self.render_response('test.html', **context)
File "/Users/scott/svn/GAE_branches/sample_broken_app/handlers.py", line 14, in render_response
rv = self.jinja2.render_template(_template, **context)
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/webapp2/webapp2_extras/jinja2.py", line 158, in render_template
return self.environment.get_template(_filename).render(**context)
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/jinja2/jinja2/environment.py", line 719, in get_template
return self._load_template(name, self.make_globals(globals))
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/jinja2/jinja2/environment.py", line 693, in _load_template
template = self.loader.load(self, name, globals)
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/jinja2/jinja2/loaders.py", line 115, in load
source, filename, uptodate = self.get_source(environment, name)
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/jinja2/jinja2/loaders.py", line 165, in get_source
f = open_if_exists(filename)
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/jinja2/jinja2/utils.py", line 224, in open_if_exists
return open(filename, mode)
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/tools/dev_appserver_import_hook.py", line 592, in __init__
raise IOError(errno.EACCES, 'file not accessible', filename)
IOError: [Errno 13] file not accessible: 'templates/test.html'
ERROR 2012-02-14 21:54:04,991 wsgi.py:205]
Traceback (most recent call last):
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/runtime/wsgi.py", line 193, in Handle
result = handler(self._environ, self._StartResponse)
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/webapp2/webapp2.py", line 1519, in __call__
response = self._internal_error(e)
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/webapp2/webapp2.py", line 1511, in __call__
rv = self.handle_exception(request, response, e)
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/webapp2/webapp2.py", line 1505, in __call__
rv = self.router.dispatch(request, response)
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/webapp2/webapp2.py", line 1253, in default_dispatcher
return route.handler_adapter(request, response)
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/webapp2/webapp2.py", line 1077, in __call__
return handler.dispatch()
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/webapp2/webapp2.py", line 547, in dispatch
return self.handle_exception(e, self.app.debug)
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/webapp2/webapp2.py", line 545, in dispatch
return method(*args, **kwargs)
File "/Users/scott/svn/GAE_branches/sample_broken_app/handlers.py", line 21, in get
self.render_response('test.html', **context)
File "/Users/scott/svn/GAE_branches/sample_broken_app/handlers.py", line 14, in render_response
rv = self.jinja2.render_template(_template, **context)
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/webapp2/webapp2_extras/jinja2.py", line 158, in render_template
return self.environment.get_template(_filename).render(**context)
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/jinja2/jinja2/environment.py", line 719, in get_template
return self._load_template(name, self.make_globals(globals))
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/jinja2/jinja2/environment.py", line 693, in _load_template
template = self.loader.load(self, name, globals)
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/jinja2/jinja2/loaders.py", line 115, in load
source, filename, uptodate = self.get_source(environment, name)
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/jinja2/jinja2/loaders.py", line 165, in get_source
f = open_if_exists(filename)
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/jinja2/jinja2/utils.py", line 224, in open_if_exists
return open(filename, mode)
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/tools/dev_appserver_import_hook.py", line 592, in __init__
raise IOError(errno.EACCES, 'file not accessible', filename)
IOError: [Errno 13] file not accessible: 'templates/test.html'
INFO 2012-02-14 21:54:05,006 dev_appserver.py:2884] "GET /test HTTP/1.1" 500 -
The app is just:
handlers.py:
import webapp2
from webapp2_extras import jinja2
class BaseHandler(webapp2.RequestHandler):
#webapp2.cached_property
def jinja2(self):
# Returns a Jinja2 renderer cached in the app registry.
return jinja2.get_jinja2(app=self.app)
def render_response(self, _template, **context):
# Renders a template and writes the result to the response.
rv = self.jinja2.render_template(_template, **context)
self.response.write(rv)
class MyHandler(BaseHandler):
def get(self):
context = {'message': 'Hello, world!'}
self.render_response('test.html', **context)
webapp2_config = {}
webapp2_config['webapp2_extras.sessions'] = {
'secret_key': 'ef23fsdawe444',
}
application = webapp2.WSGIApplication([
webapp2.Route(r'/test', handler=MyHandler, name='test'),
], debug=True, config=webapp2_config)
app.yaml:
application: sampleapp
version: 0-01
api_version: 1
runtime: python27
threadsafe: false
builtins:
- remote_api: on
handlers:
- url: .*
script: handlers.application
libraries:
- name: jinja2
version: 2.6
- name: webapp2
version: 2.3
There's also a templates directory with test.html in it.
Now when I run the app from a different directory, it works fine.
This google python group post gave me a hint to try a different directory, but I have no idea what's wrong with the original, which ran versions of the code without jinja2 from webapp2_extras fine.
Version info:
OS X 10.6.8,
GoogleAppEngineLauncher: 1.6.2,
Python: 2.7.2
I reinstalled everything, and set my PYTHONPATH to "" in my .bash_profile, but that didn't change anything.
Note: I did strip out a few of the non public directory names from the debug output, but they didn't have spaces or anything.
A few others had a similar error, but their fixes were for older versions. There seems to be something about os.path
root folder and any folder you set in app.yaml as static dir won't work with jinja2 FileSystemLoader
While you're deploying, the value of upload_dir will go into CDN instead of GAE instance, though you're currently in local development server, App Engine SDK prevent you load files from where you couldn't find on production.
I was getting this error of yours, but without using the jinja2 from webapp2_extras (I was creating a jinja_enviroment myself, like
jinja_environment = jinja2.Environment(loader=jinja2.FileSystemLoader(os.path.dirname(__file__)))
). I solved it by ignoring that os.path.dirname(__file__) that is in the docs and just putting
jinja_environment = jinja2.Environment(loader=jinja2.FileSystemLoader('templates'))
So I thought I could help, but tried to solve your problem and nothing came. But when you said
A few others had a similar error, but their fixes were for older
versions. There seems to be something about os.path
what did you mean? Are you using os.path in some part of the code? Because os.path is problematic and webapp2_extras.jinja2 don't use it, it just creates the environment with 'templates' handwritten as the template directory. Check the source.
So, maybe there's a hint somewhere in this comment. Good luck.