Diagnosing an Internal Server Error in GAE - python-2.7

Traceback (most recent call last):
File "/base/alloc/tmpfs/dynamic_runtimes/python27/a7637d5531ec9deb_unzipped/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py", line 1535, in __call__
rv = self.handle_exception(request, response, e)
File "/base/alloc/tmpfs/dynamic_runtimes/python27/a7637d5531ec9deb_unzipped/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py", line 1529, in __call__
rv = self.router.dispatch(request, response)
File "/base/alloc/tmpfs/dynamic_runtimes/python27/a7637d5531ec9deb_unzipped/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py", line 1278, in default_dispatcher
return route.handler_adapter(request, response)
File "/base/alloc/tmpfs/dynamic_runtimes/python27/a7637d5531ec9deb_unzipped/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py", line 1102, in __call__
return handler.dispatch()
File "/base/alloc/tmpfs/dynamic_runtimes/python27/a7637d5531ec9deb_unzipped/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/alloc/tmpfs/dynamic_runtimes/python27/a7637d5531ec9deb_unzipped/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~dkc-app/20180221t133719.407817416956265792/manage/admin.py", line 13, in get
applicants, applications = query.get_all_overview()
File "/base/data/home/apps/s~dkc-app/20180221t133719.407817416956265792/manage/query.py", line 52, in get_all_overview
applications = ndb.get_multi(application_keys)
File "/base/alloc/tmpfs/dynamic_runtimes/python27/a7637d5531ec9deb_unzipped/python27_lib/versions/1/google/appengine/ext/ndb/model.py", line 3931, in get_multi
for future in get_multi_async(keys, **ctx_options)]
File "/base/alloc/tmpfs/dynamic_runtimes/python27/a7637d5531ec9deb_unzipped/python27_lib/versions/1/google/appengine/ext/ndb/model.py", line 3916, in get_multi_async
return [key.get_async(**ctx_options) for key in keys]
AttributeError: 'NoneType' object has no attribute 'get_async'
This suddenly started happening a few weeks ago and I have not been able to figure out what happened. My best guess is that updating gcloud components caused it since nothing else changed.

try changing:
applications = ndb.get_multi(application_keys)
to
applications = ndb.get_multi([key for key in application_keys if key])
it looks like one of your keys is None

Related

Localstack : Creating stack from cloudformation file which refer to some existing reources

I am trying to deploy a stack using localstack.
My cloudformation file refer to few existing resources which are already created on the dev environment.
While deploying my cloudformation I am getting below errors:
2022-10-03T10:17:26.431 DEBUG --- [ Thread-256] l.u.c.template_deployer : Error applying changes for CloudFormation stack "ashford1": An error occurred (InternalError) when calling the AttachRolePolicy operation (reached max retries: 4): exception while calling iam.AttachRolePolicy: Traceback (most recent call last):
File "/opt/code/localstack/localstack/aws/chain.py", line 90, in handle
handler(self, self.context, response)
File "/opt/code/localstack/localstack/aws/handlers/service.py", line 122, in __call__
handler(chain, context, response)
File "/opt/code/localstack/localstack/aws/handlers/service.py", line 92, in __call__
skeleton_response = self.skeleton.invoke(context)
File "/opt/code/localstack/localstack/aws/skeleton.py", line 153, in invoke
return self.dispatch_request(context, instance)
File "/opt/code/localstack/localstack/aws/skeleton.py", line 165, in dispatch_request
result = handler(context, instance) or {}
File "/opt/code/localstack/localstack/aws/forwarder.py", line 60, in _call
return fallthrough_handler(context, req)
File "/opt/code/localstack/localstack/services/moto.py", line 83, in _proxy_moto
return call_moto(context)
File "/opt/code/localstack/localstack/services/moto.py", line 46, in call_moto
return dispatch_to_backend(context, dispatch_to_moto, include_response_metadata)
File "/opt/code/localstack/localstack/aws/forwarder.py", line 113, in dispatch_to_backend
http_response = http_request_dispatcher(context)
File "/opt/code/localstack/localstack/services/moto.py", line 111, in dispatch_to_moto
status, headers, content = dispatch(request, request.url, request.headers)
File "/opt/code/localstack/.venv/lib/python3.10/site-packages/moto/core/responses.py", line 217, in dispatch
return cls()._dispatch(*args, **kwargs)
File "/opt/code/localstack/.venv/lib/python3.10/site-packages/moto/core/responses.py", line 356, in _dispatch
return self.call_action()
File "/opt/code/localstack/.venv/lib/python3.10/site-packages/moto/core/responses.py", line 443, in call_action
response = method()
File "/opt/code/localstack/.venv/lib/python3.10/site-packages/moto/iam/responses.py", line 17, in attach_role_policy
self.backend.attach_role_policy(policy_arn, role_name)
File "/opt/code/localstack/.venv/lib/python3.10/site-packages/moto/iam/models.py", line 1689, in attach_role_policy
policy = arns[policy_arn]
KeyError: 'arn:aws:iam::XXXXX:policy/BasePolicy-Default-XXX'
Traceback (most recent call last):
File "/opt/code/localstack/localstack/utils/cloudformation/template_deployer.py", line 1569, in _run
self.do_apply_changes_in_loop(changes, stack)
File "/opt/code/localstack/localstack/utils/cloudformation/template_deployer.py", line 1646, in do_apply_changes_in_loop
self.apply_change(change, stack=stack)
File "/opt/code/localstack/localstack/utils/cloudformation/template_deployer.py", line 1723, in apply_change
result = deploy_resource(self, resource_id)
File "/opt/code/localstack/localstack/utils/cloudformation/template_deployer.py", line 853, in deploy_resource
result = execute_resource_action(resource_id, stack, ACTION_CREATE)
File "/opt/code/localstack/localstack/utils/cloudformation/template_deployer.py", line 891, in execute_resource_action
result = func["function"](resource_id, resources, resource_type, func, stack_name)
File "/opt/code/localstack/localstack/services/cloudformation/models/iam.py", line 294, in _post_create
iam.attach_role_policy(RoleName=role_name, PolicyArn=arn)
File "/opt/code/localstack/.venv/lib/python3.10/site-packages/botocore/client.py", line 514, in _api_call
return self._make_api_call(operation_name, kwargs)
File "/opt/code/localstack/.venv/lib/python3.10/site-packages/botocore/client.py", line 938, in _make_api_call
raise error_class(parsed_response, operation_name)
botocore.exceptions.ClientError: An error occurred (InternalError) when calling the AttachRolePolicy operation (reached max retries: 4): exception while calling iam.AttachRolePolicy: Traceback (most recent call last):
File "/opt/code/localstack/localstack/aws/chain.py", line 90, in handle
handler(self, self.context, response)
File "/opt/code/localstack/localstack/aws/handlers/service.py", line 122, in __call__
handler(chain, context, response)
File "/opt/code/localstack/localstack/aws/handlers/service.py", line 92, in __call__
skeleton_response = self.skeleton.invoke(context)
File "/opt/code/localstack/localstack/aws/skeleton.py", line 153, in invoke
return self.dispatch_request(context, instance)
File "/opt/code/localstack/localstack/aws/skeleton.py", line 165, in dispatch_request
result = handler(context, instance) or {}
File "/opt/code/localstack/localstack/aws/forwarder.py", line 60, in _call
return fallthrough_handler(context, req)
File "/opt/code/localstack/localstack/services/moto.py", line 83, in _proxy_moto
return call_moto(context)
File "/opt/code/localstack/localstack/services/moto.py", line 46, in call_moto
return dispatch_to_backend(context, dispatch_to_moto, include_response_metadata)
File "/opt/code/localstack/localstack/aws/forwarder.py", line 113, in dispatch_to_backend
http_response = http_request_dispatcher(context)
File "/opt/code/localstack/localstack/services/moto.py", line 111, in dispatch_to_moto
status, headers, content = dispatch(request, request.url, request.headers)
File "/opt/code/localstack/.venv/lib/python3.10/site-packages/moto/core/responses.py", line 217, in dispatch
return cls()._dispatch(*args, **kwargs)
File "/opt/code/localstack/.venv/lib/python3.10/site-packages/moto/core/responses.py", line 356, in _dispatch
return self.call_action()
File "/opt/code/localstack/.venv/lib/python3.10/site-packages/moto/core/responses.py", line 443, in call_action
response = method()
File "/opt/code/localstack/.venv/lib/python3.10/site-packages/moto/iam/responses.py", line 17, in attach_role_policy
self.backend.attach_role_policy(policy_arn, role_name)
File "/opt/code/localstack/.venv/lib/python3.10/site-packages/moto/iam/models.py", line 1689, in attach_role_policy
policy = arns[policy_arn]
KeyError: 'arn:aws:iam::XXXXXXXXXXXX:policy/Policy-Default-XXXX'
My questions:
Should I create the existing resources manually before deploying the stack?
Can I create the stack with multiple resource files places in cloudformation.d folder? As of now, I need to create a single cloudformation.yml file and use that to deploy stack.
Thanks for your time and help.

Boto AttributeError: 'module' object has no attribute 'HTTPSConnection'

I am working in ubuntu 18.04 and Google App Engine python2.7. Because working with python2.7 I can only use boto and not boto3. I am however receiving this error and can't seem to fix it...
ERROR 2021-05-12 12:17:29,792 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)
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'
Absolutely clueless and any help is appreciated..
See these 2 links. They're both for Python2.6 but they might be similar to Python2.7 or point you in the right direction
HTTPSConnection module missing in Python 2.6 on CentOS 5.2
https://groups.google.com/g/google-analytics-data-export-api/c/JkGWM10-4Bw?pli=1

python-selenium on aws lambda throws error when switch_back_to.default_content and try to select element

python-selenium using phantomjs used to open an iFrame inside the page, then after switching back to the default content(driver.switch_to.default_content()) does not work.
The following is a pseudo code snippet to explain the scenario.
frame = WebDriverWait(driver, wait_time).until(EC.frame_to_be_available_and_switch_to_it((By.CSS_SELECTOR, "iframe.class_name")))
......
driver.switch_to.default_content()
print('Switched back to default content')
# Error occurs when line below is interpreted
driver.find_element_by_css_selector("div[title^='Test %s']" %(array_of_content[1]))
Following error occurs:-
Traceback (most recent call last):
File "/var/task/main.py", line 217, in test_method
driver.find_element_by_css_selector("div[title^='Test %s']" %(array_of_content[1]))
File "/var/task/selenium/webdriver/support/wait.py", line 71, in until
value = method(self._driver)
File "/var/task/selenium/webdriver/support/expected_conditions.py", line 213, in __call__
element = visibility_of_element_located(self.locator)(driver)
File "/var/task/selenium/webdriver/support/expected_conditions.py", line 78, in __call__
return _element_if_visible(_find_element(driver, self.locator))
File "/var/task/selenium/webdriver/support/expected_conditions.py", line 307, in _find_element
return driver.find_element(*by)
File "/var/task/selenium/webdriver/remote/webdriver.py", line 752, in find_element
'value': value})['value']
File "/var/task/selenium/webdriver/remote/webdriver.py", line 234, in execute
response = self.command_executor.execute(driver_command, params)
File "/var/task/selenium/webdriver/remote/remote_connection.py", line 401, in execute
return self._request(command_info[0], url, body=data)
File "/var/task/selenium/webdriver/remote/remote_connection.py", line 471, in _request
resp = opener.open(request, timeout=self._timeout)
File "/usr/lib64/python2.7/urllib2.py", line 431, in open
response = self._open(req, data)
File "/usr/lib64/python2.7/urllib2.py", line 449, in _open
'_open', req)
File "/usr/lib64/python2.7/urllib2.py", line 409, in _call_chain
result = func(*args)
File "/usr/lib64/python2.7/urllib2.py", line 1229, in http_open
return self.do_open(httplib.HTTPConnection, req)
File "/usr/lib64/python2.7/urllib2.py", line 1202, in do_open
r = h.getresponse(buffering=True)
File "/var/task/raven/breadcrumbs.py", line 328, in getresponse
rv = real_getresponse(self, *args, **kwargs)
File "/usr/lib64/python2.7/httplib.py", line 1132, in getresponse
response.begin()
File "/usr/lib64/python2.7/httplib.py", line 453, in begin
version, status, reason = self._read_status()
File "/usr/lib64/python2.7/httplib.py", line 417, in _read_status
raise BadStatusLine(line)
BadStatusLine: ''
Any ideas, what is happening.
As I am able to see the same error, even if I write driver.save_screenshot('test.png').
But it is not throwing any error on local machines, also tried to use AMI instance to replicate if something is there in concern Amazon Linux.

How do I fix this KeyError error using Flask-SocketIO?

This seems to be a common problem when I search around, but I can't seem to find a viable resolution. The error is not very helpful as far as I can tell as it doesn't really tell you why the saved session is gone.
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/eventlet/wsgi.py", line 481, in handle_one_response
result = self.application(self.environ, start_response)
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1836, in __call__
return self.wsgi_app(environ, start_response)
File "/usr/local/lib/python2.7/dist-packages/flask_socketio/__init__.py", line 37, in __call__
start_response)
File "/usr/local/lib/python2.7/dist-packages/engineio/middleware.py", line 47, in __call__
return self.engineio_app.handle_request(environ, start_response)
File "/usr/local/lib/python2.7/dist-packages/socketio/server.py", line 303, in handle_request
return self.eio.handle_request(environ, start_response)
File "/usr/local/lib/python2.7/dist-packages/engineio/server.py", line 226, in handle_request
environ, start_response)
File "/usr/local/lib/python2.7/dist-packages/engineio/socket.py", line 79, in handle_get_request
start_response)
File "/usr/local/lib/python2.7/dist-packages/engineio/socket.py", line 118, in _upgrade_websocket
return ws(environ, start_response)
File "/usr/local/lib/python2.7/dist-packages/engineio/async_eventlet.py", line 13, in __call__
return super(WebSocketWSGI, self).__call__(environ, start_response)
File "/usr/local/lib/python2.7/dist-packages/eventlet/websocket.py", line 127, in __call__
self.handler(ws)
File "/usr/local/lib/python2.7/dist-packages/engineio/socket.py", line 180, in _websocket_handler
self.receive(pkt)
File "/usr/local/lib/python2.7/dist-packages/engineio/socket.py", line 48, in receive
self.server._trigger_event('message', self.sid, pkt.data)
File "/usr/local/lib/python2.7/dist-packages/engineio/server.py", line 330, in _trigger_event
return self.handlers[event](*args)
File "/usr/local/lib/python2.7/dist-packages/socketio/server.py", line 429, in _handle_eio_message
self._handle_event(sid, pkt.namespace, pkt.id, pkt.data)
File "/usr/local/lib/python2.7/dist-packages/socketio/server.py", line 371, in _handle_event
r = self._trigger_event(data[0], namespace, sid, *data[1:])
File "/usr/local/lib/python2.7/dist-packages/socketio/server.py", line 397, in _trigger_event
return self.handlers[namespace][event](*args)
File "/usr/local/lib/python2.7/dist-packages/flask_socketio/__init__.py", line 199, in _handler
self.server.environ[sid]['saved_session'] = {}
KeyError: 'baee47721e474a1a9885b41ee0ce1847'
First of all, upgrade the following packages: flask-socketio, python-socketio and python-engineio.
I think that will address your issues. This problem occurred with older versions of Flask-SocketIO. The cause that I identified for this condition was that a handler function (these functions you decorate with socketio.on() decorator) ran for a very long time without properly releasing the CPU. If the function ran for longer than 60 seconds without releasing the CPU, then the system mistakenly considered that the client was gone and disconnected the session, causing a KeyError when that session was accessed later.
The error is addressed in the latest release. But also please make sure you release the CPU so that other tasks that run in the background get a chance to do what they need to do.

500 Internal Server Error after remove addon Odoo V8

I uninstalled an addon by mistake and has caused me an internal server error, the log file reads:
2016-01-07 00:26:27,355 8253 CRITICAL bitnami_openerp openerp.service.server: Failed to initialize database `bitnami_openerp`.
Traceback (most recent call last):
File "/opt/bitnami/apps/odoo/lib/odoo-8.0_20150423-py2.7.egg/openerp/service/server.py", line 919, in preload_registries
registry = RegistryManager.new(dbname, update_module=update_module)
File "/opt/bitnami/apps/odoo/lib/odoo-8.0_20150423-py2.7.egg/openerp/modules/registry.py", line 368, in new
openerp.modules.load_modules(registry._db, force_demo, status, update_module)
File "/opt/bitnami/apps/odoo/lib/odoo-8.0_20150423-py2.7.egg/openerp/modules/loading.py", line 357, in load_modules
registry.setup_models(cr)
File "/opt/bitnami/apps/odoo/lib/odoo-8.0_20150423-py2.7.egg/openerp/modules/registry.py", line 192, in setup_models
model._setup_fields(cr, SUPERUSER_ID)
File "/opt/bitnami/apps/odoo/lib/odoo-8.0_20150423-py2.7.egg/openerp/api.py", line 241, in wrapper
return old_api(self, *args, **kwargs)
File "/opt/bitnami/apps/odoo/lib/odoo-8.0_20150423-py2.7.egg/openerp/api.py", line 336, in old_api
result = method(recs, *args, **kwargs)
File "/opt/bitnami/apps/odoo/lib/odoo-8.0_20150423-py2.7.egg/openerp/models.py", line 2987, in _setup_fields
field.setup(self.env)
File "/opt/bitnami/apps/odoo/lib/odoo-8.0_20150423-py2.7.egg/openerp/fields.py", line 453, in setup
self._setup_related(env)
File "/opt/bitnami/apps/odoo/lib/odoo-8.0_20150423-py2.7.egg/openerp/fields.py", line 499, in _setup_related
field = recs._fields[name]
KeyError: 'formated_vat'
It would be great if you could help me, please.