i've just approached Google App Engine. I've joined a project without having a clue about how it work so i'm sorry if this question looks dumb.
My problem is that looking at the log, it says it cannot import ndb. I've looked up for that a bit and discovered this should be present by default in version 1.6.4 of the google app engine.
I've tried to import it from console and it doesn't work either. My installation of python and google app engine are clean, i did both today.
What should i do?
I'm working on windows with python 2.7 and google app engine 1.6.4.
This is the line of code giving me problems:
from wtforms.ext.appengine.ndb import model_form
Here is the error:
INFO 2012-04-10 19:44:34,582 dev_appserver.py:2884] "GET /
HTTP/1.1" 500 - ERROR 2012-04-10 19:47:05,239 wsgi.py:189]
Traceback (most recent call last): File "C:\Program Files
(x86)\Google\google_appengine\google\appengine\runtime\wsgi.py", line
187, in Handle
handler = _config_handle.add_wsgi_middleware(self._LoadHandler()) File "C:\Program Files
(x86)\Google\google_appengine\google\appengine\runtime\wsgi.py", line
236, in _LoadHandler
import(cumulative_path) File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\dev_appserver_import_hook.py",
line 676, in Decorate
return func(self, *args, **kwargs) File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\dev_appserver_import_hook.py",
line 1850, in load_module
return self.FindAndLoadModule(submodule, fullname, search_path) File "C:\Program Files
(x86)\Google\google_appengine\google\appengine\tools\dev_appserver_import_hook.py",
line 676, in Decorate
return func(self, *args, **kwargs) File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\dev_appserver_import_hook.py",
line 1722, in FindAndLoadModule
description) File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\dev_appserver_import_hook.py",
line 676, in Decorate
return func(self, *args, **kwargs) File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\dev_appserver_import_hook.py",
line 1665, in LoadModuleRestricted
description) File "C:\Users\chobeat\workspace\pappa Mi\py\main.py", line 38, in
from py.comments import * File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\dev_appserver_import_hook.py",
line 676, in Decorate
return func(self, *args, **kwargs) File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\dev_appserver_import_hook.py",
line 1850, in load_module
return self.FindAndLoadModule(submodule, fullname, search_path) File "C:\Program Files
(x86)\Google\google_appengine\google\appengine\tools\dev_appserver_import_hook.py",
line 676, in Decorate
return func(self, *args, **kwargs) File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\dev_appserver_import_hook.py",
line 1722, in FindAndLoadModule
description) File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\dev_appserver_import_hook.py",
line 676, in Decorate
return func(self, *args, **kwargs) File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\dev_appserver_import_hook.py",
line 1665, in LoadModuleRestricted
description) File "C:\Users\chobeat\workspace\pappa Mi\py\comments.py", line 20, in
from py.form import IspezioneForm, NonconformitaForm, DietaForm, NotaForm File "C:\Program Files
(x86)\Google\google_appengine\google\appengine\tools\dev_appserver_import_hook.py",
line 676, in Decorate
return func(self, *args, **kwargs) File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\dev_appserver_import_hook.py",
line 1850, in load_module
return self.FindAndLoadModule(submodule, fullname, search_path) File "C:\Program Files
(x86)\Google\google_appengine\google\appengine\tools\dev_appserver_import_hook.py",
line 676, in Decorate
return func(self, *args, **kwargs) File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\dev_appserver_import_hook.py",
line 1722, in FindAndLoadModule
description) File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\dev_appserver_import_hook.py",
line 676, in Decorate
return func(self, *args, **kwargs) File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\dev_appserver_import_hook.py",
line 1665, in LoadModuleRestricted
description) File "C:\Users\chobeat\workspace\pappa Mi\py\form.py", line 6, in
from wtforms.ext.appengine.ndb import model_form ImportError: No module named ndb
You need to import it like this:
from google.appengine.ext import ndb
If you just say import ndb you are missing out on some import path information. Don't be afraid to copy the code that is having trouble into your question. Often, that will provide the vital clue.
UPDATE:
WTForms is not included as part of the AppEngine SDK. You'll need to install it on your system.
from wtforms.ext.appengine.ndb import model_form
can't work. wtforms does not have a ndb package.
it should be:
from wtforms.ext.appengine.db import model_form
Related
I'm using the AWS CDK to run lambda functions locally. I have followed a couple of tutorials on setting this up but I appear to be getting issues when invoking the function with SAM. The typical error I encounter is below:
Invoking handler.handle (python3.9)
PypassLambdaLayer0643FC6D is a local Layer in the template
Image was not found.
Building image...Traceback (most recent call last):
File "runpy.py", line 194, in _run_module_as_main
File "runpy.py", line 87, in _run_code
File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\samcli\__main__.py", line 12, in <module>
cli(prog_name="sam")
File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\click\core.py", line 829, in __call__
return self.main(*args, **kwargs)
File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\click\core.py", line 782, in main
rv = self.invoke(ctx)
File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\click\core.py", line 1259, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\click\core.py", line 1259, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\click\core.py", line 1066, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\click\core.py", line 610, in invoke
return callback(*args, **kwargs)
File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\click\decorators.py", line 73, in new_func
return ctx.invoke(f, obj, *args, **kwargs)
File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\click\core.py", line 610, in invoke
return callback(*args, **kwargs)
File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\samcli\lib\telemetry\metric.py", line 166, in wrapped
raise exception # pylint: disable=raising-bad-type
File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\samcli\lib\telemetry\metric.py", line 124, in wrapped
return_value = func(*args, **kwargs)
File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\samcli\lib\utils\version_checker.py", line 41, in wrapped
actual_result = func(*args, **kwargs)
File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\samcli\cli\main.py", line 87, in wrapper
return func(*args, **kwargs)
File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\samcli\commands\local\invoke\cli.py", line 85, in cli
do_cli(
File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\samcli\commands\local\invoke\cli.py", line 182, in do_cli
context.local_lambda_runner.invoke(
File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\samcli\commands\local\lib\local_lambda.py", line 137, in invoke
self.local_runtime.invoke(
File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\samcli\lib\telemetry\metric.py", line 230, in wrapped_func
return_value = func(*args, **kwargs)
File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\samcli\local\lambdafn\runtime.py", line 177, in invoke
container = self.create(function_config, debug_context, container_host, container_host_interface)
File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\samcli\local\lambdafn\runtime.py", line 73, in create
container = LambdaContainer(
File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\samcli\local\docker\lambda_container.py", line 93, in __init__
image = LambdaContainer._get_image(
File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\samcli\local\docker\lambda_container.py", line 236, in _get_image
return lambda_image.build(runtime, packagetype, image, layers, architecture, function_name=function_name)
File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\samcli\local\docker\lambda_image.py", line 163, in build
self._build_image(
File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\samcli\local\docker\lambda_image.py", line 261, in _build_image
with create_tarball(tar_paths, tar_filter=tar_filter) as tarballfile:
File "contextlib.py", line 113, in __enter__
File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\samcli\lib\utils\tar.py", line 29, in create_tarball archive.add(path_on_system, arcname=path_in_tarball, filter=tar_filter)
File "tarfile.py", line 1977, in add
File "tarfile.py", line 1977, in add
File "tarfile.py", line 1977, in add
[Previous line repeated 1 more time]
File "tarfile.py", line 1955, in add
File "tarfile.py", line 1834, in gettarinfo
FileNotFoundError: [WinError 3] The system cannot find the path specified: 'C:\\Users\\LeeBarrett\\OneDrive - LumiraDx Group Ltd\\Documents\\pypass_dev\\2022\\pypass_connect_lambda\\cdk.out\\asset.60e64357ce064cf62274b8d1a8976ceb2903f31abd576090b450010d30b4ac7a\\python\\numpy\\.libs\\libopenblas.FB5AE2TYXYH2IJRDKGDGQ3XBKLKTF43H.gfortran-win_amd64.dll'
I've had multiple errors similar to that above but sometimes the file that is (apparently) missing is different. It looks like an issue with building the image rather than the stack code itself but I'm unsure and couldn't find any other similar issues.
The code I am using in the Stack class object is below:
pypass_lambda_layer = _lambda.LayerVersion(self, "PypassLambdaLayer", code=_lambda.Code.from_asset("lambda/layers"), compatible_runtimes=[_lambda.Runtime.PYTHON_3_9])
my_lambda = _lambda.Function(self, "Pypasshandler", runtime=_lambda.Runtime.PYTHON_3_9, code=_lambda.Code.from_asset("lambda/code"), handler="handler.handle", layers=[pypass_lambda_layer])
Tutorials I tried to follow:
https://dev.to/upupkenchoong/how-to-provision-lambda-and-lambda-layer-with-cdk-2ff4
https://medium.com/geekculture/deploying-aws-lambda-layers-with-python-8b15e24bdad2
The layers folder referenced in the LayerVersion function contains another folder called python which has pandas installed in it.
\lambda
\layers
\python
\code
handler.py
I'm on a windows machine and I have the cdk packages installed in conda virtual environment.
Any help would be greatly appreciated.
Thanks
I am trying to import a large User Information list from a json file to the datastore using taskqueue and deferred.
A User contains the user's information including an image url from a different app. During the importing process, the image should be grabbed and uploaded to the blob (which works just fine when tested).
I got stuck with getting the blob_key of the uploaded image.
And I think it only occurs inside a taskqueue/deferred because I tried it inside a 'normal' GET request handler, it works just fine.
This is my handler:
class MigrationTask(BaseHandler):
def post(self):
if not self.request.get('file'):
return
json_data = open(self.request.get('file'))
data = json.load(json_data)
json_data.close()
for datum in data['results']:
deferred.defer(push_user_to_db, datum)
this are my functions:
#ndb.transactional(xg=True)
def _push_user_to_db(profilePicture=None, ...):
if profilePicture:
if 'url' in profilePicture:
con = urlfetch.fetch(image_url)
if con.status_code == 200:
file_name = files.blobstore.create(mime_type='application/octet-stream')
with files.open(file_name, 'a') as f:
f.write(con.content)
files.finalize(file_name)
blob_key = files.blobstore.get_blob_key(file_name) # this part is where it errs
image_url = images.get_serving_url(file_name)
# some codes here...
def push_user_to_db(kwargs):
_push_user_to_db(**kwargs)
part of the traceback:
blob_key = files.blobstore.get_blob_key(file_name)
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\api\files\blobstore.py", line 132, in get_blob_key
namespace='')])[0]
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\api\datastore.py", line 654, in Get
return GetAsync(keys, **kwargs).get_result()
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\api\datastore.py", line 629, in GetAsync
return _GetConnection().async_get(config, keys, local_extra_hook)
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\datastore\datastore_rpc.py", line 1574, in async_get
pbs = [key_to_pb(key) for key in keys]
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\ext\ndb\model.py", line 653, in key_to_pb
return key.reference()
AttributeError: 'Key' object has no attribute 'reference'
PS: I've also tried taskqueue instead of deferred.
EDIT(1):
This is the traceback:
ERROR 2015-03-03 06:32:44,720 webapp2.py:1552] 'Key' object has no attribute 'reference'
Traceback (most recent call last):
File "C:\Program Files (x86)\Google\google_appengine\lib\webapp2-2.5.2\webapp2.py", line 1535, in __call__
rv = self.handle_exception(request, response, e)
File "C:\Program Files (x86)\Google\google_appengine\lib\webapp2-2.5.2\webapp2.py", line 1529, in __call__
rv = self.router.dispatch(request, response)
File "C:\Program Files (x86)\Google\google_appengine\lib\webapp2-2.5.2\webapp2.py", line 1278, in default_dispatcher
return route.handler_adapter(request, response)
File "C:\Program Files (x86)\Google\google_appengine\lib\webapp2-2.5.2\webapp2.py", line 1102, in __call__
return handler.dispatch()
File "C:\Program Files (x86)\Google\google_appengine\lib\webapp2-2.5.2\webapp2.py", line 572, in dispatch
return self.handle_exception(e, self.app.debug)
File "C:\Program Files (x86)\Google\google_appengine\lib\webapp2-2.5.2\webapp2.py", line 570, in dispatch
return method(*args, **kwargs)
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\ext\deferred\deferred.py", line 310, in post
self.run_from_request()
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\ext\deferred\deferred.py", line 305, in run_from_request
run(self.request.body)
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\ext\deferred\deferred.py", line 147, in run
return func(*args, **kwds)
File "C:\project directory\migration.py", line 141, in push_user_to_db
_push_user_to_db(**kwargs)
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\ext\ndb\utils.py", line 179, in inner_wrapper
return wrapped_decorator(func, args, kwds, **options)
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\ext\ndb\model.py", line 3759, in transactional
func, args, kwds, **options).get_result()
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\ext\ndb\tasklets.py", line 325, in get_result
self.check_success()
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\ext\ndb\tasklets.py", line 371, in _help_tasklet_along
value = gen.send(val)
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\ext\ndb\context.py", line 999, in transaction
result = callback()
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\ext\ndb\model.py", line 3767, in <lambda>
return transaction_async(lambda: func(*args, **kwds), **options)
File "C:\project directory\migration.py", line 56, in _push_user_to_db
blob_key = files.blobstore.get_blob_key(file_name)
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\api\files\blobstore.py", line 132, in get_blob_key
namespace='')])[0]
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\api\datastore.py", line 654, in Get
return GetAsync(keys, **kwargs).get_result()
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\api\datastore.py", line 629, in GetAsync
return _GetConnection().async_get(config, keys, local_extra_hook)
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\datastore\datastore_rpc.py", line 1574, in async_get
pbs = [key_to_pb(key) for key in keys]
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\ext\ndb\model.py", line 653, in key_to_pb
return key.reference()
AttributeError: 'Key' object has no attribute 'reference'
Heads up! Writing files to the Blobstore using the files api has been deprecated. I had this issue before. My codes run perfectly fine in development server (localhost) but erred on App Engine server. The solution is to write the files in the Google Cloud Storage via Blobstore API.
I have post here about which I learned later that gae has moved here.
Basically I tried django-nonrel example, replacing its django with django-1.3.1 since I coded my app on it but it gives some basic error like cannot find django.db.utils. Note that I have created symbolic link from django -> Django-1.3.1/django and hope its not the issue.
Bases upon replies if I try to use django-nonrel version in my app similar to sample app I get error as below as if its cannot find sqlite3 backend though it mentions as one option in its choices. Also again utils.py is not found.
--> --> -->
Traceback (most recent call last):
File "c:\Program Files\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 4143, in _HandleRequest
self._Dispatch(dispatcher, self.rfile, outfile, env_dict)
File "c:\Program Files\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 4049, in _Dispatch
base_env_dict=env_dict)
File "c:\Program Files\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 616, in Dispatch
base_env_dict=base_env_dict)
File "c:\Program Files\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 3120, in Dispatch
self._module_dict)
File "c:\Program Files\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 3024, in ExecuteCGI
reset_modules = exec_script(handler_path, cgi_path, hook)
File "c:\Program Files\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 2887, in ExecuteOrImportScript
exec module_code in script_module.__dict__
File "I:\learn\python\event\djangoappengine\main\main.py", line 97, in <module>
main()
File "I:\learn\python\event\djangoappengine\main\main.py", line 56, in real_main
run_wsgi_app(application)
File "c:\Program Files\Google\google_appengine\google\appengine\ext\webapp\util.py", line 98, in run_wsgi_app
run_bare_wsgi_app(add_wsgi_middleware(application))
File "c:\Program Files\Google\google_appengine\google\appengine\ext\webapp\util.py", line 116, in run_bare_wsgi_app
result = application(env, _start_response)
File "I:\learn\python\event\django\core\handlers\wsgi.py", line 265, in __call__
response = self.get_response(request)
File "I:\learn\python\event\django\core\handlers\base.py", line 160, in get_response
response = self.handle_uncaught_exception(request, resolver, sys.exc_info())
File "I:\learn\python\event\django\core\handlers\base.py", line 194, in handle_uncaught_exception
return debug.technical_500_response(request, *exc_info)
File "I:\learn\python\event\django\views\debug.py", line 58, in technical_500_response
html = reporter.get_traceback_html()
File "I:\learn\python\event\django\views\debug.py", line 109, in get_traceback_html
frames = self.get_traceback_frames()
File "I:\learn\python\event\django\views\debug.py", line 228, in get_traceback_frames
pre_context_lineno, pre_context, context_line, post_context = self._get_lines_from_file(filename, lineno, 7, loader, module_name)
File "I:\learn\python\event\django\views\debug.py", line 180, in _get_lines_from_file
source = loader.get_source(module_name)
File "c:\Program Files\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 1538, in Decorate
return func(self, *args, **kwargs)
File "c:\Program Files\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 2518, in get_source
full_path, search_path, submodule = self.GetModuleInfo(fullname)
File "c:\Program Files\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 1538, in Decorate
return func(self, *args, **kwargs)
File "c:\Program Files\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 2482, in GetModuleInfo
submodule, search_path = self.GetParentSearchPath(fullname)
File "c:\Program Files\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 1538, in Decorate
return func(self, *args, **kwargs)
File "c:\Program Files\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 2461, in GetParentSearchPath
parent_package = self.GetParentPackage(fullname)
File "c:\Program Files\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 1538, in Decorate
return func(self, *args, **kwargs)
File "c:\Program Files\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 2437, in GetParentPackage
if self.find_module(fullname) is None:
File "c:\Program Files\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 1538, in Decorate
return func(self, *args, **kwargs)
File "c:\Program Files\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 2045, in find_module
search_path)
File "c:\Program Files\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 1538, in Decorate
return func(self, *args, **kwargs)
File "c:\Program Files\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 2375, in FindAndLoadModule
description)
File "c:\Program Files\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 1538, in Decorate
return func(self, *args, **kwargs)
File "c:\Program Files\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 2318, in LoadModuleRestricted
description)
File "I:\learn\python\event\django\db\__init__.py", line 77, in <module>
connection = connections[DEFAULT_DB_ALIAS]
File "I:\learn\python\event\django\db\utils.py", line 91, in __getitem__
backend = load_backend(db['ENGINE'])
File "I:\learn\python\event\django\db\utils.py", line 49, in load_backend
raise ImproperlyConfigured(error_msg)
ImproperlyConfigured: 'django.db.backends.sqlite3' isn't an available database backend.
Try using django.db.backends.XXX, where XXX is one of:
'dummy', 'mysql', 'oracle', 'postgresql', 'postgresql_psycopg2', 'sqlite3'
Error was: cannot import name utils
what version of django is compatible with django-nonrel or do I have to do development using django-nonrel instead of Django-1.3.1 ?
As I read more on django-nonrel I feel that there are few modification needed to django code. Its not straight forward to just use the project as it is. I need to create abstract model super class and it does not support manytomanyfield which I use in my project.
I guess some one confirm these restriction then probably I can close this thread.
March 28
I removed M2M from my app. It was very minor thing just commented out M2M field.
Now I have installed python2.7.2, gae 1.6.4 and djangoappengine gives error as below:
E:\learn\python\event>python manage.py runserver
WARNING:root:E:\software\Google\google_appengine\lib\cacerts\urlfetch_cacerts.tx
t missing; without this urlfetch will not be able to validate SSL certificates.
Traceback (most recent call last):
File "manage.py", line 4, in <module>
import settings # Assumed to be in the same directory.
File "E:\learn\python\event\settings.py", line 4, in <module>
from djangoappengine.settings_base import *
File "E:\learn\python\event\djangoappengine\settings_base.py", line 6, in <mod
ule>
setup_env()
File "E:\learn\python\event\djangoappengine\boot.py", line 69, in setup_env
setup_project()
File "E:\learn\python\event\djangoappengine\boot.py", line 123, in setup_proje
ct
from .utils import have_appserver, on_production_server
File "E:\learn\python\event\djangoappengine\utils.py", line 14, in <module>
default_partition='dev')[0]
TypeError: LoadAppConfig() got an unexpected keyword argument 'default_partition
'
Regards,
Miten.
You can't just replace the version of Django in nonrel. It's actually a fork of Django, with a number of customizations.
Django-1.3.1/Django's database models do not work on Google App Engine.
Django-nonrel implements a backend so that Django models will work on Google App Engine.
So if you want to use Django models, you must use Django-nonrel. Otherwise, you can use Django for templating/forms, but you need to use Google App Engine's db.Model or ndb.Model based models.
I copied my httplib2 directory into my GAE project, and now I'm getting the following error:
line 64, in <module> _ssl_wrap_socket = ssl.wrap_socket
Is this an issue with Google App Engine, or did I somehow install my httplib2 incorrectly?
Full error dump, as request(it's big!):
--> --> -->
Traceback (most recent call last):
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 4053, in _HandleRequest
self._Dispatch(dispatcher, self.rfile, outfile, env_dict)
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 3977, in _Dispatch
base_env_dict=env_dict)
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 588, in Dispatch
base_env_dict=base_env_dict)
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 3050, in Dispatch
self._module_dict)
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 2954, in ExecuteCGI
reset_modules = exec_script(handler_path, cgi_path, hook)
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 2834, in ExecuteOrImportScript
exec module_code in script_module.__dict__
File "C:\Users\quaunaut\Documents\Aptana Studio 3 Workspace\qushoutout\src\main.py", line 25, in <module>
import twitter as twitter
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 1505, in Decorate
return func(self, *args, **kwargs)
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 2450, in load_module
return self.FindAndLoadModule(submodule, fullname, search_path)
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 1505, in Decorate
return func(self, *args, **kwargs)
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 2339, in FindAndLoadModule
description)
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 1505, in Decorate
return func(self, *args, **kwargs)
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 2282, in LoadModuleRestricted
description)
File "C:\Users\quaunaut\Documents\Aptana Studio 3 Workspace\qushoutout\src\twitter.py", line 65, in <module>
import oauth2 as oauth
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 1505, in Decorate
return func(self, *args, **kwargs)
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 2450, in load_module
return self.FindAndLoadModule(submodule, fullname, search_path)
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 1505, in Decorate
return func(self, *args, **kwargs)
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 2339, in FindAndLoadModule
description)
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 1505, in Decorate
return func(self, *args, **kwargs)
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 2282, in LoadModuleRestricted
description)
File "C:\Users\quaunaut\Documents\Aptana Studio 3 Workspace\qushoutout\src\oauth2\__init__.py", line 32, in <module>
import httplib2
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 1505, in Decorate
return func(self, *args, **kwargs)
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 2450, in load_module
return self.FindAndLoadModule(submodule, fullname, search_path)
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 1505, in Decorate
return func(self, *args, **kwargs)
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 2339, in FindAndLoadModule
description)
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 1505, in Decorate
return func(self, *args, **kwargs)
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 2282, in LoadModuleRestricted
description)
File "C:\Users\quaunaut\Documents\Aptana Studio 3 Workspace\qushoutout\src\httplib2\__init__.py", line 64, in <module>
_ssl_wrap_socket = ssl.wrap_socket
AttributeError: 'module' object has no attribute 'wrap_socket'
Still having this issue. About the only thing I can think of that could possibly be causing this is my machine running Python 2.7; Is it possible that is causing the issue?
As a workaround:
Can you use Google App Engine SDK 1.4.3 (this looks like a 1.5.0 regression).
Or force httplib2 fallback on httplib.FakeSocket with:
import sys
sys.modules['ssl'] = None
import httplib2
A new issue has been filled there:
http://code.google.com/p/googleappengine/issues/detail?id=5064
It looks already fixed in httplib2 side:
http://code.google.com/p/httplib2/source/detail?r=cf721c1693a68e9438899be3d78acccae6ab0e30#
The AppEngine sandbox doesn't allow access to a sockets API, for an http library to work on GAE it would have to wrap urllib (which in turn wraps the url_fetch API).
EDIT Looks like httplib2 should work so I guess you just need to ensure your paths are setup correctly.
See this question
This Blog claims to fix the GAE issues. I haven't tried it yet, but sounds right.
My code worked fine when it was all in one file. Now, I'm splitting up classes into different modules. The modules have been given the same name as the classes. Perhaps this is a problem, because MainPage is failing when it is loaded. Does it think that I'm trying to inherit from a module? Can module/class namespace collisions happen?
MainPage.py
import BaseHandler
from models import Item
from Utils import render
class MainPage(BaseHandler):
def body(self, CSIN=None): ##UnusedVariable
self.header('Store')
items = Item.all().order('name').fetch(10)
render('Views/table.html', self, {'items': items})
self.footer()
BaseHandler.py
from google.appengine.ext import webapp
from google.appengine.api import users
from Utils import *
# Controller
class BaseHandler(webapp.RequestHandler):
# ... continues ...
Failure traceback:
Traceback (most recent call last):
File "C:\Program Files\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 3180, in _HandleRequest
self._Dispatch(dispatcher, self.rfile, outfile, env_dict)
File "C:\Program Files\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 3123, in _Dispatch
base_env_dict=env_dict)
File "C:\Program Files\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 515, in Dispatch
base_env_dict=base_env_dict)
File "C:\Program Files\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 2382, in Dispatch
self._module_dict)
File "C:\Program Files\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 2292, in ExecuteCGI
reset_modules = exec_script(handler_path, cgi_path, hook)
File "C:\Program Files\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 2188, in ExecuteOrImportScript
exec module_code in script_module.__dict__
File "C:\Users\odp\workspace\Store\src\Main.py", line 5, in <module>
import MainPage
File "C:\Program Files\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 1267, in Decorate
return func(self, *args, **kwargs)
File "C:\Program Files\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 1917, in load_module
return self.FindAndLoadModule(submodule, fullname, search_path)
File "C:\Program Files\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 1267, in Decorate
return func(self, *args, **kwargs)
File "C:\Program Files\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 1819, in FindAndLoadModule
description)
File "C:\Program Files\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 1267, in Decorate
return func(self, *args, **kwargs)
File "C:\Program Files\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 1770, in LoadModuleRestricted
description)
File "C:\Users\odp\workspace\Store\src\MainPage.py", line 10, in <module>
class MainPage(BaseHandler):
TypeError: Error when calling the metaclass bases
module.__init__() takes at most 2 arguments (3 given)
It appears this can be solved by using
from BaseHandler import BaseHandler
Is it bad style to have the module and class name be the same?
Yes, module names share the same namespace as everything else, and, yes, Python thinks you are trying to inherit from a module.
Change:
class MainPage(BaseHandler):
to:
class MainPage(BaseHandler.BaseHandler):
and you should be good to go. That way, you're saying "please inherit from the BaseHandler class in the BaseHandler module".
Alternately, you could change:
import BaseHandler
to:
from BaseHandler import BaseHandler
First of all the filenames should be all lowercase. That's Python convention that helps to avoid confusion such as this, at least most of the time.
Next, your import from withing MainHandler.py is wrong. You are importing BaseHandler (the module) and referencing it as if it were a class. The class is actually BaseHandler.BaseHandler. You need to reference it as such.
Try that and it should work for you.