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.
Related
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!
I use requests library (or urllib3), trying to get xml page from web site. And my code is working, but when i use it in app engine it shows an error
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\Kirill\Desktop\Schedule\Schedule\main.py", line 51, in get
class_list = get_class_list()
File "C:\Users\Kirill\Desktop\Schedule\Schedule\get_class_urllib3.py", line 6, in get_class_list
r = http.request('POST', 'http://sgo.volganet.ru/lacc.asp?Function=GetClassListForSchool&SchoolID=1460')
File "C:\Users\Kirill\Desktop\Schedule\Schedule\urllib3\request.py", line 73, in request
**urlopen_kw)
File "C:\Users\Kirill\Desktop\Schedule\Schedule\urllib3\request.py", line 151, in request_encode_body
return self.urlopen(method, url, **extra_kw)
File "C:\Users\Kirill\Desktop\Schedule\Schedule\urllib3\poolmanager.py", line 165, in urlopen
response = conn.urlopen(method, u.request_uri, **kw)
File "C:\Users\Kirill\Desktop\Schedule\Schedule\urllib3\connectionpool.py", line 558, in urlopen
body=body, headers=headers)
File "C:\Users\Kirill\Desktop\Schedule\Schedule\urllib3\connectionpool.py", line 389, in _make_request
assert_header_parsing(httplib_response.msg)
File "C:\Users\Kirill\Desktop\Schedule\Schedule\urllib3\util\response.py", line 49, in assert_header_parsing
type(headers)))
TypeError: expected httplib.Message, got <type 'instance'>.
So can you help me to fix this problem or suggest any module I can use in app angine to create post request to differen site.
I would recommend using the API provided by AppEngine: urlfetch.fetch()
I get this internal server error whenever I run the code. I'm trying to save the content of a page I retrieved, into datastore by splitting it into a list of words. basically it's a crawler, and has to save each word and the url of the page as a pair.
here is the traceback:
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\Samson\Documents\searchengineapp\searchapp\crawlHandler.py", line 26, in post
if spider.crawl_web():
File "C:\Users\Samson\Documents\searchengineapp\searchapp\crawl\crawler.py", line 52, in crawl_web
add_page_to_index(page, content)
File "C:\Users\Samson\Documents\searchengineapp\searchapp\crawl\indexin.py", line 42, in add_page_to_index
add_to_index(word, url)
File "C:\Users\Samson\Documents\searchengineapp\searchapp\crawl\indexin.py", line 29, in add_to_index
index.put()
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\ext\ndb\model.py", line 3432, in _put
return self._put_async(**ctx_options).get_result()
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\ext\ndb\tasklets.py", line 326, in get_result
self.check_success()
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\ext\ndb\tasklets.py", line 369, in _help_tasklet_along
value = gen.throw(exc.__class__, exc, tb)
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\ext\ndb\context.py", line 810, in put
key = yield self._put_batcher.add(entity, options)
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\ext\ndb\tasklets.py", line 369, in _help_tasklet_along
value = gen.throw(exc.__class__, exc, tb)
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\ext\ndb\context.py", line 343, in _put_tasklet
keys = yield self._conn.async_put(options, datastore_entities)
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\ext\ndb\tasklets.py", line 455, in _on_rpc_completion
result = rpc.get_result()
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\api\apiproxy_stub_map.py", line 613, in get_result
return self.__get_result_hook(self)
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\datastore\datastore_rpc.py", line 1881, in __put_hook
self.check_rpc_success(rpc)
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\datastore\datastore_rpc.py", line 1371, in check_rpc_success
rpc.check_success()
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\api\apiproxy_stub_map.py", line 579, in check_success
self.__rpc.CheckSuccess()
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\api\apiproxy_rpc.py", line 157, in _WaitImpl
self.request, self.response)
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\ext\remote_api\remote_api_stub.py", line 201, in MakeSyncCall
self._MakeRealSyncCall(service, call, request, response)
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\ext\remote_api\remote_api_stub.py", line 227, in _MakeRealSyncCall
encoded_response = self._server.Send(self._path, encoded_request)
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\appengine_rpc.py", line 394, in Send
response = f.read()
File "C:\Python27\lib\socket.py", line 351, in read
data = self._sock.recv(rbufsize)
File "C:\Python27\lib\httplib.py", line 549, in read
return self._read_chunked(amt)
File "C:\Python27\lib\httplib.py", line 603, in _read_chunked
raise IncompleteRead(''.join(value))
IncompleteRead: IncompleteRead(52 bytes read)
I honestly don't know where the problem is coming from. please I need help. Thanks
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.
I have a problem, I want to access the data which are stocked in my google cloud storage but I have an error and I don't know where it comes from.
Here is my code :
DECORATOR = oauth2decorator_from_clientsecrets(
CLIENT_SECRETS,
scope=[
'https://www.googleapis.com/auth/devstorage.read_only',
],
message=MISSING_CLIENT_SECRETS_MESSAGE)
http = DECORATOR.http()
service_cloud = build("storage", "v1beta1")
list_response = service_cloud.objects().list(bucket="directory_structure").execute(http=http)
params = {'directory_list':list_response['items']}
return self.render_template('directoryChoice.html', **params)
and the error message I receive is:
Traceback (most recent call last):
File "/python27_runtime/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py", line 1529, in __call__ rv = self.router.dispatch(request, response)
File "/python27_runtime/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py", line 1278, in default_dispatcher return route.handler_adapter(request, response)
File "/python27_runtime/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py", line 1102, in __call__ return handler.dispatch()
File "/base/data/home/apps/s~jba-gae-boilerplate/dev.366111306063368728/boilerplate/lib/basehandler.py", line 162, in dispatch webapp2.RequestHandler.dispatch(self)
File "/python27_runtime/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py", line 572, in dispatch return self.handle_exception(e, self.app.debug)
File "/python27_runtime/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~jba-gae-boilerplate/dev.366111306063368728/web/lib/oauth2client/appengine.py", line 469, in check_oauth return method(request_handler, *args, **kwargs)
File "/base/data/home/apps/s~jba-gae-boilerplate/dev.366111306063368728/web/handlers.py", line 190, in get list_response = service_cloud.objects().list(bucket="jba_directory").execute(http=http)
File "/base/data/home/apps/s~jba-gae-boilerplate/dev.366111306063368728/web/lib/oauth2client/util.py", line 120, in positional_wrapper return wrapped(*args, **kwargs)
File "/base/data/home/apps/s~jba-gae-boilerplate/dev.366111306063368728/web/lib/apiclient/http.py", line 678, in execute raise HttpError(resp, content, uri=self.uri)
HttpError:
One thing which looks a bit odd:
In your code you're listing the directory_structure bucket, but the traceback references jba_directory. There is a mis-match of some sort. Perhaps in a wrapping decorator or other code above the snippet you included here?