Python Google App Engine Internal Server Error - python

I am new to app engine and trying to deploy a python app. The app works correctly when I preview it on my local host but when I deploy it I get the following error: "Internal Server Error
The server has either erred or is incapable of performing the requested operation."
And traceback:
Traceback (most recent call last):
File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py", line 1535, in __call__
rv = self.handle_exception(request, response, e)
File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py", line 1529, in __call__
rv = self.router.dispatch(request, response)
File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py", line 1278, in default_dispatcher
return route.handler_adapter(request, response)
File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py", line 1102, in __call__
return handler.dispatch()
File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py", line 572, in dispatch
return self.handle_exception(e, self.app.debug)
File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py", line 570, in dispatch
return method(*args, **kwargs)
File "/base/data/home/apps/s~ecd-signup/20160620t104611.393644814392119591/hpvball.py", line 78, in get
entries_c = qry_c.fetch(100)
File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/ext/ndb/utils.py", line 160, in positional_wrapper
return wrapped(*args, **kwds)
File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/ext/ndb/query.py", line 1203, in fetch
return self.fetch_async(limit, **q_options).get_result()
File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/ext/ndb/tasklets.py", line 383, in get_result
self.check_success()
File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/ext/ndb/tasklets.py", line 427, in _help_tasklet_along
value = gen.throw(exc.__class__, exc, tb)
File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/ext/ndb/query.py", line 980, in _run_to_list
batch = yield rpc
File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/ext/ndb/tasklets.py", line 513, in _on_rpc_completion
result = rpc.get_result()
File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/api/apiproxy_stub_map.py", line 613, in get_result
return self.__get_result_hook(self)
File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/datastore/datastore_query.py", line 2921, in __query_result_hook
yaml_index=yaml, xml_index=xml)
NeedIndexError: no matching index found. recommended index is:
- kind: Entry
ancestor: yes
properties:
- name: committed
- name: date
The suggested index for this query is:
- kind: Entry
ancestor: yes
properties:
- name: committed
- name: date

If this is a new/recent deployment of the app it's possible for the newly added/modified indexes to be still building, the condition is transitory and will eventually go away. See this answer: https://stackoverflow.com/a/29807764/4495081.
It's possible in some cases that the suggested index is not automatically generated by the local development server. Check your local index file for the existance of the suggested index. If missing add it manually.
It's also possible in some cases (some multi-module apps, for example) that the app deployment doesn't automatically upload the local app index file. If the indexes displayed in the developer console don't match those you see in the local index file you should deploy them explicitly, using the update_indexes appcfg.py option.

Related

Google App engine python2.7 Boto AttributeError: 'module' object has no attribute 'HTTPSConnection'

I am recently working on a project that uses Google App Engine running on python2.7 on Ubuntu18.04. Files need to be uploaded to AWS S3, so we are using boto for this. However running the code outside the app works but when running it inside GAE it gives me the following error:
ERROR 2021-05-12 03:54:54,582 webapp2.py:1552] 'module' object has no attribute 'HTTPSConnection'
Traceback (most recent call last):
File "/home/depotter/Downloads/google-cloud-sdk-282.0.0-linux-x86_64/google-cloud-sdk/platform/google_appengine/lib/webapp2-2.5.2/webapp2.py", line 1535, in __call__
rv = self.handle_exception(request, response, e)
File "/home/depotter/Downloads/google-cloud-sdk-282.0.0-linux-x86_64/google-cloud-sdk/platform/google_appengine/lib/webapp2-2.5.2/webapp2.py", line 1529, in __call__
rv = self.router.dispatch(request, response)
File "/home/depotter/Downloads/google-cloud-sdk-282.0.0-linux-x86_64/google-cloud-sdk/platform/google_appengine/lib/webapp2-2.5.2/webapp2.py", line 1278, in default_dispatcher
return route.handler_adapter(request, response)
File "/home/depotter/Downloads/google-cloud-sdk-282.0.0-linux-x86_64/google-cloud-sdk/platform/google_appengine/lib/webapp2-2.5.2/webapp2.py", line 1102, in __call__
return handler.dispatch()
File "/home/depotter/Downloads/google-cloud-sdk-282.0.0-linux-x86_64/google-cloud-sdk/platform/google_appengine/lib/webapp2-2.5.2/webapp2.py", line 572, in dispatch
return self.handle_exception(e, self.app.debug)
File "/home/depotter/Downloads/google-cloud-sdk-282.0.0-linux-x86_64/google-cloud-sdk/platform/google_appengine/lib/webapp2-2.5.2/webapp2.py", line 570, in dispatch
return method(*args, **kwargs)
File "/home/depotter/projects/mwcentral/server/./online_ordering/ctg/menu.py", line 204, in post
self.send_menu(company_key, store_id, timestamp)
File "/home/depotter/projects/mwcentral/server/./online_ordering/ctg/menu.py", line 257, in send_menu
result = self.upload_menu(menu, company_key_id, store_id)
File "/home/depotter/projects/mwcentral/server/./online_ordering/ctg/menu.py", line 295, in upload_menu
key.set_contents_from_string(file)
File "/home/depotter/projects/mwcentral/lib/boto/s3/key.py", line 1442, in set_contents_from_string
encrypt_key=encrypt_key)
File "/home/depotter/projects/mwcentral/lib/boto/s3/key.py", line 1309, in set_contents_from_file
chunked_transfer=chunked_transfer, size=size)
File "/home/depotter/projects/mwcentral/lib/boto/s3/key.py", line 762, in send_file
chunked_transfer=chunked_transfer, size=size)
File "/home/depotter/projects/mwcentral/lib/boto/s3/key.py", line 963, in _send_file_internal
query_args=query_args
File "/home/depotter/projects/mwcentral/lib/boto/s3/connection.py", line 671, in make_request
retry_handler=retry_handler
File "/home/depotter/projects/mwcentral/lib/boto/connection.py", line 1071, in make_request
retry_handler=retry_handler)
File "/home/depotter/projects/mwcentral/lib/boto/connection.py", line 913, in _mexe
self.is_secure)
File "/home/depotter/projects/mwcentral/lib/boto/connection.py", line 705, in get_http_connection
return self.new_http_connection(host, port, is_secure)
INFO 2021-05-12 03:54:54,590 module.py:865] remote-ordering: "POST /api/ctg/tasks/menu/send HTTP/1.1" 500 3685
WARNING 2021-05-12 03:54:54,590 taskqueue_stub.py:2149] Task task2 failed to execute. This task will retry in 40.000 seconds
File "/home/depotter/projects/mwcentral/lib/boto/connection.py", line 755, in new_http_connection
connection = http_client.HTTPSConnection(
AttributeError: 'module' object has no attribute 'HTTPSConnection'
Any help is appreciated!

Server Internal Error in google app engine using python

import webapp2
import mysql.connector
class MainHandler(webapp2.RequestHandler):
def get(self):
db=mysql.connector.connect(host="localhost",user="root",password="bsit",database="registration")
mycursor=db.cursor()
mycursor.execute("select * from student")
result=mycursor.fetchall()
self.response.write(str(result))
app = webapp2.WSGIApplication([('/', MainHandler)], debug=True)
Internal Server Error
The server has either erred or is incapable of performing the requested operation.
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:\Users\Aaqib Nadeem\Desktop\db-test\main.py", line 6, in get
db=mysql.connector.connect(host="localhost",user="root",password="bsit",database="registration")
File "C:\Python27\lib\mysql\connector\__init__.py", line 162, in connect
return MySQLConnection(*args, **kwargs)
File "C:\Python27\lib\mysql\connector\connection.py", line 129, in __init__
self.connect(**kwargs)
File "C:\Python27\lib\mysql\connector\connection.py", line 454, in connect
self._open_connection()
File "C:\Python27\lib\mysql\connector\connection.py", line 418, in _open_connection
self._do_handshake()
File "C:\Python27\lib\mysql\connector\connection.py", line 141, in _do_handshake
packet = self._socket.recv()
File "C:\Python27\lib\mysql\connector\network.py", line 255, in recv_plain
errno=2055, values=(self.get_address(), _strioerror(err)))
OperationalError: 2055: Lost connection to MySQL server at 'localhost:3306', system error:
Please provide a solution of this error
There is no way to use MySQL with Google App Engine. You can use GAE Cloud SQL instead.

What the error with ConjunctionNode() means?

My application experiences over quota issues and I would like to handle such cases properly in my code. The limit is reached just for Datastore Read Operations, but I get TypeError: ConjunctionNode() requires at least one node exception when try to read the data from the memcache - entries = memcache.get('mykey').
Why this exception happens?
Exception details:
Traceback (most recent call last):
File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 266, in Handle
result = handler(dict(self._environ), self._StartResponse)
File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.3/webapp2.py", line 1519, in __call__
response = self._internal_error(e)
File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.3/webapp2.py", line 1511, in __call__
rv = self.handle_exception(request, response, e)
File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.3/webapp2.py", line 1505, in __call__
rv = self.router.dispatch(request, response)
File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.3/webapp2.py", line 1253, in default_dispatcher
return route.handler_adapter(request, response)
File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.3/webapp2.py", line 1077, in __call__
return handler.dispatch()
File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.3/webapp2.py", line 547, in dispatch
return self.handle_exception(e, self.app.debug)
File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.3/webapp2.py", line 545, in dispatch
return method(*args, **kwargs)
File "/base/data/home/apps/s~myapp/1.373233284460557570/myapp.py", line 595, in get
entries = memcache.get('mykey')
File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/api/memcache/__init__.py", line 559, in get
results = rpc.get_result()
File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/api/apiproxy_stub_map.py", line 612, in get_result
return self.__get_result_hook(self)
File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/api/memcache/__init__.py", line 624, in __get_hook
self._do_unpickle)
File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/api/memcache/__init__.py", line 271, in _decode_value
return do_unpickle(value)
File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/api/memcache/__init__.py", line 401, in _do_unpickle
return unpickler.load()
File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/ext/ndb/query.py", line 550, in __new__
raise TypeError('ConjunctionNode() requires at least one node.')
TypeError: ConjunctionNode() requires at least one node.
Upd. here is what I save to memcache:
entries = MyModel.query()
entries = entries.fetch(keys_only=True)
entries = random.sample(entries, 10)
entries = [list_key.get() for list_key in entries]
memcache.set('mykey', entries, 60*60*24)
Upd2. Online memcache viewer shows the following value stored (just first part is shown below):
Type: Object
..cgoogle.appengine.ext.ndb.query.Query.q.).q.}q.(U._Query__projectionq.NU._Query__filtersq.cgoogle.appengine.ext.ndb.query.ConjunctionNode.q.).q.}q.U._ConjunctionNode__nodesq.]q.(cgoogle.appengine.ext.ndb.query.FilterNode.q.).q.}q.(U._Filt
I believe that this happens simply because you are trying to put a pickled Query object into memcache, but Query objects are not pickle-able.
What I do instead in this case is to convert the Query to a list prior to putting it into the cache. If your code doesn't care about the distinction (that is, if it's not calling .filter() or something like that) then it'll probably work fine for you too.

App Engine - getting KeyError with memcache implementation

I'm trying to implement the code that Guido posted as an answer to the question Avoiding Memcache 1M limit of values. Everything seems(?) to be working when I first load the page and add values to memcache, but when I re-load it and retrieve values from the memcache I get a strange error:
Traceback (most recent call last):
File "/base/python27_runtime/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 194, in Handle
for chunk in result:
File "/base/python27_runtime/python27_lib/versions/1/google/appengine/ext/appstats/recording.py", line 1036, in appstats_wsgi_wrapper
result = app(environ, appstats_start_response)
File "/base/python27_runtime/python27_lib/versions/third_party/webapp2-2.3/webapp2.py", line 1519, in __call__
response = self._internal_error(e)
File "/base/python27_runtime/python27_lib/versions/third_party/webapp2-2.3/webapp2.py", line 1511, in __call__
rv = self.handle_exception(request, response, e)
File "/base/python27_runtime/python27_lib/versions/third_party/webapp2-2.3/webapp2.py", line 1505, in __call__
rv = self.router.dispatch(request, response)
File "/base/python27_runtime/python27_lib/versions/third_party/webapp2-2.3/webapp2.py", line 1253, in default_dispatcher
return route.handler_adapter(request, response)
File "/base/python27_runtime/python27_lib/versions/third_party/webapp2-2.3/webapp2.py", line 1077, in __call__
return handler.dispatch()
File "/base/python27_runtime/python27_lib/versions/third_party/webapp2-2.3/webapp2.py", line 547, in dispatch
return self.handle_exception(e, self.app.debug)
File "/base/python27_runtime/python27_lib/versions/third_party/webapp2-2.3/webapp2.py", line 545, in dispatch
return method(*args, **kwargs)
File "/appengineurlhere/mypythoncode.py", line 87, in get
entitylist = retrieve("entitylist")
File "/appengineurlhere/mypythoncode.py", line 53, in retrieve
return pickle.loads(serialized)
File "/base/python27_runtime/python27_dist/lib/python2.7/pickle.py", line 1382, in loads
return Unpickler(file).load()
File "/base/python27_runtime/python27_dist/lib/python2.7/pickle.py", line 858, in load
dispatch[key](self)
KeyError: ':'
Here's the store/retrieve code:
def store(key, value, chunksize=750000):
serialized = pickle.dumps(value, 2)
values = {}
for i in xrange(0, len(serialized), chunksize):
values['%s.%s' % (key, i//chunksize)] = serialized[i : i+chunksize]
memcache.set_multi(values)
def retrieve(key):
result = memcache.get_multi(['%s.%s' % (key, i) for i in xrange(32)])
serialized = ''.join([v for v in result.values() if v is not None])
return pickle.loads(serialized)
And this is how I'm using it:
try:
entitylist = retrieve("entitylist")
except EOFError:
entitylist = MyModel.all().fetch(None)
store("entitylist", entitylist)
Other oddities:
I don't see this on my development server; just the production App Engine site. (Though the data on my development server is slightly different; I believe it all fits into the standard 1MB memcache size, where the production data is larger.)
When I search for "entitylist" on both my development and production admin panel, App Engine tells me "no such key". Yet based on the total size of the memcache shown (this is the only place I've implemented memcache), it absolutely appears that something is getting cached.
Can anyone please point me in the direction of something I should look at or fix?
Is it possible that you have some old instances of MyModel that don't match with the current definition of MyModel? You could get errors while pickling if there are unrecognized or missing attributes.

How to use gaesessions in google-app-engine

I'm new to Python (as well as GAE), I'm trying to include gaesessions in my application, this is exactly what I did:
I copied the gaesessions folder to my src folder (the folder includes __init__.py file)
and added this to my working code:
from gaesessions import get_current_session
session = get_current_session()
I received the following error:
Traceback (most recent call last): File "C:\Program
Files\Google\google_appengine\google\appengine\runtime\wsgi.py", line
174, in Handle
result = handler(self._environ, self._StartResponse)
File "C:\Program
Files\Google\google_appengine\lib\webapp2\webapp2.py", line 1519, in
__call__
response = self._internal_error(e)
File "C:\Program
Files\Google\google_appengine\lib\webapp2\webapp2.py", line 1511, in
__call__
rv = self.handle_exception(request, response, e)
File "C:\Program
Files\Google\google_appengine\lib\webapp2\webapp2.py", line 1505, in
__call__
rv = self.router.dispatch(request, response)
File "C:\Program
Files\Google\google_appengine\lib\webapp2\webapp2.py", line 1253, in
default_dispatcher
return route.handler_adapter(request, response)
File "C:\Program
Files\Google\google_appengine\lib\webapp2\webapp2.py", line 1077, in
__call__
return handler.dispatch()
File "C:\Program
Files\Google\google_appengine\lib\webapp2\webapp2.py", line 547, in
dispatch
return self.handle_exception(e, self.app.debug)
File "C:\Program
Files\Google\google_appengine\lib\webapp2\webapp2.py", line 545, in
dispatch
return method(*args, **kwargs)
File "D:....\src\helloworld.py", line 13, in get
session = get_current_session()
File "D:....\src\gaesessions\__init__.py", line 36, in
get_current_session
return _tls.current_session
File "C:\Python27\lib\_threading_local.py", line 193, in
__getattribute__
return object.__getattribute__(self, name)
You've omitted the actual exception from your stack trace, but I'm guessing it's this:
AttributeError: 'local' object has no attribute 'current_session'
If so, you've most likely skipped the middleware configuration step. Create an appengine_config.py per the instructions and restart the dev server; this should resolve your error.

Categories

Resources