Trouble deploying django app to AWS lambda using zappa - python-3.x

I am trying to deploy my django app to AWS Lambda. I have viewed many tutorials on how to do so. However, whenever I run zappa deploy, I get the following error at the end:
Deploying API Gateway.. Error: Warning! Status check on the deployed lambda failed. A GET request to '/' yielded a 502 response code.
Running zappa tail gives me the following:
[1604786373569] [DEBUG] 2020-11-07T21:59:33.569Z 1a7e8cd4-1bf2-4af4-b11b-2baa6c6691dc Read environment variables from: /var/task/my_cool_project/.env
[1604786373570] [DEBUG] 2020-11-07T21:59:33.569Z 1a7e8cd4-1bf2-4af4-b11b-2baa6c6691dc get 'SECRET_KEY' casted as 'None' with default '<NoValue>'
[1604786373582] [DEBUG] 2020-11-07T21:59:33.582Z 1a7e8cd4-1bf2-4af4-b11b-2baa6c6691dc get 'DB_ENGINE' casted as 'None' with default '<NoValue>'
[1604786373582] [DEBUG] 2020-11-07T21:59:33.582Z 1a7e8cd4-1bf2-4af4-b11b-2baa6c6691dc get 'DB_NAME' casted as 'None' with default '<NoValue>'
[1604786373582] [DEBUG] 2020-11-07T21:59:33.582Z 1a7e8cd4-1bf2-4af4-b11b-2baa6c6691dc get 'DB_USER' casted as 'None' with default '<NoValue>'
[1604786373582] [DEBUG] 2020-11-07T21:59:33.582Z 1a7e8cd4-1bf2-4af4-b11b-2baa6c6691dc get 'DB_PASSWORD' casted as 'None' with default '<NoValue>'
[1604786373582] [DEBUG] 2020-11-07T21:59:33.582Z 1a7e8cd4-1bf2-4af4-b11b-2baa6c6691dc get 'DB_HOST' casted as 'None' with default '<NoValue>'
[1604786373582] [DEBUG] 2020-11-07T21:59:33.582Z 1a7e8cd4-1bf2-4af4-b11b-2baa6c6691dc get 'DB_PORT' casted as 'None' with default '<NoValue>'
[1604786374005] [ERROR] NameError: name '_mysql' is not defined
Traceback (most recent call last):
File "/var/task/handler.py", line 609, in lambda_handler
return LambdaHandler.lambda_handler(event, context)
File "/var/task/handler.py", line 240, in lambda_handler
handler = cls()
File "/var/task/handler.py", line 146, in __init__
wsgi_app_function = get_django_wsgi(self.settings.DJANGO_SETTINGS)
File "/var/task/zappa/ext/django_zappa.py", line 20, in get_django_wsgi
return get_wsgi_application()
File "/var/task/django/core/wsgi.py", line 12, in get_wsgi_application
django.setup(set_prefix=False)
File "/var/task/django/__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "/var/task/django/apps/registry.py", line 114, in populate
app_config.import_models()
File "/var/task/django/apps/config.py", line 211, in import_models
self.models_module = import_module(models_module_name)
File "/var/lang/lib/python3.8/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 783, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/var/task/django/contrib/auth/models.py", line 2, in <module>
from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager
File "/var/task/django/contrib/auth/base_user.py", line 48, in <module>
class AbstractBaseUser(models.Model):
File "/var/task/django/db/models/base.py", line 122, in __new__
new_class.add_to_class('_meta', Options(meta, app_label))
File "/var/task/django/db/models/base.py", line 326, in add_to_class
value.contribute_to_class(cls, name)
File "/var/task/django/db/models/options.py", line 206, in contribute_to_class
self.db_table = truncate_name(self.db_table, connection.ops.max_name_length())
File "/var/task/django/db/__init__.py", line 28, in __getattr__
return getattr(connections[DEFAULT_DB_ALIAS], item)
File "/var/task/django/db/utils.py", line 214, in __getitem__
backend = load_backend(db['ENGINE'])
File "/var/task/django/db/utils.py", line 111, in load_backend
return import_module('%s.base' % backend_name)
File "/var/lang/lib/python3.8/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "/var/task/django/db/backends/mysql/base.py", line 15, in <module>
import MySQLdb as Database
File "/var/task/MySQLdb/__init__.py", line 24, in <module>
version_info, _mysql.version_info, _mysql.__file__
What am I doing wrong? I have settings.py with all my env variables defined. It seems that those variables aren't being read properly? Thanks too all of those in advance.

Not a true fix but a work around. I was using AWS RDS MySQL, and just changed everything over to AWS RDS PostgreSQL. Have had no issues. This has me to believe that the error has something to do with connecting to MySQL.

Related

Trusting self signed certificate on Amazon Linux 2

I'm aware this question has been asked like a million times but no answer or comment has helped me so far. I'm running in circles since a full week without any progress.
Situation:
I am on an Amazon Linux 2 system
I have a self-signed certificate (this is generted by iamlive - iamlive is running as a proxy and inspects all traffic to AWS endpoints to record IAM polciies)
The iamlive command looks like this:
iamlive --bind-addr "0.0.0.0:12345" --mode proxy --ca-bundle /etc/pki/ca-trust/source/anchors/iamlive.pem --ca-key /etc/pki/tls/private/iamlive.key
When the cert and key files do not exist, they will be created. When they do exist, they will be used.
After the certificate has been created I run update-ca-trust. I confirmed, then the file /etc/pki/ca-trust/extracted/openssl/ca-bundle.trust.crt includes the iamlive certificate.
Now I would expect that the whole system (except applications which hold their own certificate store) will trust this certificate.
But when I run, for example, the aws cli it will complain about a self signed certificate:
$ export HTTPS_PROXY=http://127.0.0.1:12345
$ export HTTP_PROXY=http://127.0.0.1:12345
$ aws s3 ls
SSL validation failed for https://s3.eu-central-1.amazonaws.com/ [SSL: CERTIFICATE_VERIFY_FAILED]
certificate verify failed: self signed certificate in certificate chain (_ssl.c:1091)
Of course I am aware I can tell the cli to use a specific CA bundle and that perfectly works:
$ export HTTPS_PROXY=http://127.0.0.1:12345
$ export HTTP_PROXY=http://127.0.0.1:12345
$ export AWS_CA_BUNDLE=/etc/pki/ca-trust/extracted/openssl/ca-bundle.trust.crt
$ aws s3 ls
... listing all the buckets
But here is the thing I don't get. From my understanding, the file /etc/pki/ca-trust/extracted/openssl/ca-bundle.trust.crt is what openssl should be using by default anyway. So why would it work only when I explicitly set the default file?
Now with the aws cli I can work with the env var AWS_CA_BUNDLE, which is fine.
Alternatively, there is REQUESTS_CA_BUNDLE, which does the same job, for everything that uses the python requests package, which is used by boto3 (which is used by the aws cli).
My problem is, that I need this to work with Ansible, which also uses botocore. And I have not found a way to set the CA bundle path for that, since botocore does not use the requests package.
When I run ansible-playbook (with AWS_CA_BUNDLE and REQUESTS_CA_BUNDLE both pointing to /etc/pki/ca-trust/extracted/openssl/ca-bundle.trust.crt) which execute any task that connects over http(s), I will get an error like this:
Traceback (most recent call last):
File \"/usr/local/lib/python3.7/site-packages/urllib3/connectionpool.py\", line 700, in urlopen
self._prepare_proxy(conn)
File \"/usr/local/lib/python3.7/site-packages/urllib3/connectionpool.py\", line 996, in _prepare_proxy
conn.connect()
File \"/usr/local/lib/python3.7/site-packages/urllib3/connection.py\", line 424, in connect
tls_in_tls=tls_in_tls,
File \"/usr/local/lib/python3.7/site-packages/urllib3/util/ssl_.py\", line 450, in ssl_wrap_socket
sock, context, tls_in_tls, server_hostname=server_hostname
File \"/usr/local/lib/python3.7/site-packages/urllib3/util/ssl_.py\", line 493, in _ssl_wrap_socket_impl
return ssl_context.wrap_socket(sock, server_hostname=server_hostname)
File \"/usr/lib64/python3.7/ssl.py\", line 423, in wrap_socket
session=session
File \"/usr/lib64/python3.7/ssl.py\", line 870, in _create
self.do_handshake()
File \"/usr/lib64/python3.7/ssl.py\", line 1139, in do_handshake
self._sslobj.do_handshake()
ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate in certificate chain (_ssl.c:1091)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File \"/usr/local/lib/python3.7/site-packages/botocore/httpsession.py\", line 464, in send
chunked=self._chunked(request.headers),
File \"/usr/local/lib/python3.7/site-packages/urllib3/connectionpool.py\", line 788, in urlopen
method, url, error=e, _pool=self, _stacktrace=sys.exc_info()[2]
File \"/usr/local/lib/python3.7/site-packages/urllib3/util/retry.py\", line 525, in increment
raise six.reraise(type(error), error, _stacktrace)
File \"/usr/local/lib/python3.7/site-packages/urllib3/packages/six.py\", line 769, in reraise
raise value.with_traceback(tb)
File \"/usr/local/lib/python3.7/site-packages/urllib3/connectionpool.py\", line 700, in urlopen
self._prepare_proxy(conn)
File \"/usr/local/lib/python3.7/site-packages/urllib3/connectionpool.py\", line 996, in _prepare_proxy
conn.connect()
File \"/usr/local/lib/python3.7/site-packages/urllib3/connection.py\", line 424, in connect
tls_in_tls=tls_in_tls,
File \"/usr/local/lib/python3.7/site-packages/urllib3/util/ssl_.py\", line 450, in ssl_wrap_socket
sock, context, tls_in_tls, server_hostname=server_hostname
File \"/usr/local/lib/python3.7/site-packages/urllib3/util/ssl_.py\", line 493, in _ssl_wrap_socket_impl
return ssl_context.wrap_socket(sock, server_hostname=server_hostname)
File \"/usr/lib64/python3.7/ssl.py\", line 423, in wrap_socket
session=session
File \"/usr/lib64/python3.7/ssl.py\", line 870, in _create
self.do_handshake()
File \"/usr/lib64/python3.7/ssl.py\", line 1139, in do_handshake
self._sslobj.do_handshake()
urllib3.exceptions.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate in certificate chain (_ssl.c:1091)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File \"/home/user/.ansible/tmp/ansible-tmp-1666344891.9240296-34-66835764316077/AnsiballZ_ec2_instance_info.py\", line 102, in <module>
_ansiballz_main()
File \"/home/user/.ansible/tmp/ansible-tmp-1666344891.9240296-34-66835764316077/AnsiballZ_ec2_instance_info.py\", line 94, in _ansiballz_main
invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)
File \"/home/user/.ansible/tmp/ansible-tmp-1666344891.9240296-34-66835764316077/AnsiballZ_ec2_instance_info.py\", line 40, in invoke_module
runpy.run_module(mod_name='ansible.modules.cloud.amazon.ec2_instance_info', init_globals=None, run_name='__main__', alter_sys=True)
File \"/usr/lib64/python3.7/runpy.py\", line 205, in run_module
return _run_module_code(code, init_globals, run_name, mod_spec)
File \"/usr/lib64/python3.7/runpy.py\", line 96, in _run_module_code
mod_name, mod_spec, pkg_name, script_name)
File \"/usr/lib64/python3.7/runpy.py\", line 85, in _run_code
exec(code, run_globals)
File \"/tmp/ansible_ec2_instance_info_payload_r6ce4qil/ansible_ec2_instance_info_payload.zip/ansible/modules/cloud/amazon/ec2_instance_info.py\", line 564, in <module>
File \"/tmp/ansible_ec2_instance_info_payload_r6ce4qil/ansible_ec2_instance_info_payload.zip/ansible/modules/cloud/amazon/ec2_instance_info.py\", line 560, in main
File \"/tmp/ansible_ec2_instance_info_payload_r6ce4qil/ansible_ec2_instance_info_payload.zip/ansible/modules/cloud/amazon/ec2_instance_info.py\", line 512, in list_ec2_instances
File \"/usr/local/lib/python3.7/site-packages/botocore/paginate.py\", line 479, in build_full_result
for response in self:
File \"/usr/local/lib/python3.7/site-packages/botocore/paginate.py\", line 269, in __iter__
response = self._make_request(current_kwargs)
File \"/usr/local/lib/python3.7/site-packages/botocore/paginate.py\", line 357, in _make_request
return self._method(**current_kwargs)
File \"/usr/local/lib/python3.7/site-packages/botocore/client.py\", line 514, in _api_call
return self._make_api_call(operation_name, kwargs)
File \"/usr/local/lib/python3.7/site-packages/botocore/client.py\", line 922, in _make_api_call
operation_model, request_dict, request_context
File \"/usr/local/lib/python3.7/site-packages/botocore/client.py\", line 944, in _make_request
return self._endpoint.make_request(operation_model, request_dict)
File \"/usr/local/lib/python3.7/site-packages/botocore/endpoint.py\", line 119, in make_request
return self._send_request(request_dict, operation_model)
File \"/usr/local/lib/python3.7/site-packages/botocore/endpoint.py\", line 207, in _send_request
exception,
File \"/usr/local/lib/python3.7/site-packages/botocore/endpoint.py\", line 361, in _needs_retry
request_dict=request_dict,
File \"/usr/local/lib/python3.7/site-packages/botocore/hooks.py\", line 412, in emit
return self._emitter.emit(aliased_event_name, **kwargs)
File \"/usr/local/lib/python3.7/site-packages/botocore/hooks.py\", line 256, in emit
return self._emit(event_name, kwargs)
File \"/usr/local/lib/python3.7/site-packages/botocore/hooks.py\", line 239, in _emit
response = handler(**kwargs)
File \"/usr/local/lib/python3.7/site-packages/botocore/retryhandler.py\", line 207, in __call__
if self._checker(**checker_kwargs):
File \"/usr/local/lib/python3.7/site-packages/botocore/retryhandler.py\", line 285, in __call__
attempt_number, response, caught_exception
File \"/usr/local/lib/python3.7/site-packages/botocore/retryhandler.py\", line 320, in _should_retry
return self._checker(attempt_number, response, caught_exception)
File \"/usr/local/lib/python3.7/site-packages/botocore/retryhandler.py\", line 364, in __call__
attempt_number, response, caught_exception
File \"/usr/local/lib/python3.7/site-packages/botocore/retryhandler.py\", line 248, in __call__
attempt_number, caught_exception
File \"/usr/local/lib/python3.7/site-packages/botocore/retryhandler.py\", line 416, in _check_caught_exception
raise caught_exception
File \"/usr/local/lib/python3.7/site-packages/botocore/endpoint.py\", line 281, in _do_get_response
http_response = self._send(request)
File \"/usr/local/lib/python3.7/site-packages/botocore/endpoint.py\", line 377, in _send
return self.http_session.send(request)
File \"/usr/local/lib/python3.7/site-packages/botocore/httpsession.py\", line 482, in send
raise SSLError(endpoint_url=request.url, error=e)
botocore.exceptions.SSLError: SSL validation failed for https://ec2.eu-central-1.amazonaws.com/ [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate in certificate chain (_ssl.c:1091)
Now even if there was a magic env var I could set to get this to work for Ansible, it would't be a complete solution. The same problem persists with the AWS Data Provider for SAP and probably a million more tools I haven't even tested yet.
So the question is: How to trust this self-signed cert globally, so that all apps accept it?

getting ModuleNotFoundError at /admin/login/. How to solve this error

While login in as a superuser getting this error. Below I have mentioned the installed app and middleware in settings.py and I have gotten the error named ModuleNotFoundError.
Exception Type: ModuleNotFoundError
Exception Value:
No module named 'account.backends'
Exception Location: , line 973, in _find_and_load_unlocked
Environment:
Request Method: GET
Request URL: http://127.0.0.1:8000/admin/login/?next=/admin/
Django Version: 3.2.13
Python Version: 3.8.2
Installed Applications:
['django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'chatbot_app',
'account']
Installed Middleware:
['django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware']
error
Traceback (most recent call last):
File "D:\PROJECTS\src\lib\site-packages\django\core\handlers\exception.py", line 47, in inner
response = get_response(request)
File "D:\PROJECTS\src\lib\site-packages\django\core\handlers\base.py", line 181, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "D:\PROJECTS\src\lib\site-packages\django\views\decorators\cache.py", line 44, in _wrapped_view_func
response = view_func(request, *args, **kwargs)
File "D:\PROJECTS\src\lib\site-packages\django\contrib\admin\sites.py", line 398, in login
**self.each_context(request),
File "D:\PROJECTS\src\lib\site-packages\django\contrib\admin\sites.py", line 316, in each_context
'available_apps': self.get_app_list(request),
File "D:\PROJECTS\src\lib\site-packages\django\contrib\admin\sites.py", line 505, in get_app_list
app_dict = self._build_app_dict(request)
File "D:\PROJECTS\src\lib\site-packages\django\contrib\admin\sites.py", line 450, in _build_app_dict
has_module_perms = model_admin.has_module_permission(request)
File "D:\PROJECTS\src\lib\site-packages\django\contrib\admin\options.py", line 548, in has_module_permission
return request.user.has_module_perms(self.opts.app_label)
File "D:\PROJECTS\src\lib\site-packages\django\contrib\auth\models.py", line 458, in has_module_perms
return user_has_module_perms(self, module)
File "D:\PROJECTS\src\lib\site-packages\django\contrib\auth\models.py", line 221, in user_has_module_perms
for backend in auth.get_backends():
File "D:\PROJECTS\src\lib\site-packages\django\contrib\auth_init.py", line 38, in get_backends
return get_backends(return_tuples=False)
File "D:\PROJECTS\src\lib\site-packages\django\contrib\auth_init.py", line 27, in get_backends
backend = load_backend(backend_path)
File "D:\PROJECTS\src\lib\site-packages\django\contrib\auth_init.py", line 21, in load_backend
return import_string(path)()
File "D:\PROJECTS\src\lib\site-packages\django\utils\module_loading.py", line 17, in import_string
module = import_module(module_path)
File "C:\Users\DELL\AppData\Local\Programs\Python\Python38\lib\importlib_init.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "", line 1014, in _gcd_import
File "", line 991, in _find_and_load
<source code not availabenter code herele>
File "", line 973, in _find_and_load_unlocked
Exception Type: ModuleNotFoundError at /admin/login/
Exception Value: No module named 'account. backends'

How to prevent connection timeouts while deleting SQS messages with Boto3

I have a series of AWS Lambdas that are fed from SQS queue event triggers. However, sometimes when I try to delete the message from the queue, the attempt times out over and over again until my Lambda timeout occurs.
I enabled Debug logging which confirmed it was a socket timeout, but I don't get any further details beyond that. This also appears to be irregular. At first, I thought it was a Lambda warmup issue, but I've seen the problem after running the lambda multiple times successfully and on the first deploy.
What I've tried so far:
I thought maybe using a Boto client vs a Boto resource was the problem, but I saw the same result with both methods.
I've tweaked the connection and read timeouts to be higher than the default, however, the connection just retries with the Boto retry logic under the hood.
I've tried the connection timeout to be lower, but this just means more retries before the lambda timeout.
I've tried both standard and FIFO queue types, both have the same problem
A couple of other details:
Python v3.8.5
Boto3 v1.16.1
My SQS settings are set for a 5-second delay and a 120-second visibility timeout
My lambda timeout is 120 seconds.
Snippet of the code that I'm using:
config = Config(connect_timeout=30, read_timeout=30, retries={'total_max_attempts': 1}, region_name='us-east-1')
sqs_client = boto3.client(service_name='sqs', config=config)
receiptHandle = event['Records'][0]['receiptHandle']\
fromQueueName = eventSourceARN.split(':')[-1]
fromQueue = sqs_client.get_queue_url(QueueName=fromQueueName)
fromQueueUrl = sqs_client.get_queue_url(QueueName=fromQueueName)['QueueUrl']
messageDelete = sqs_client.delete_message(QueueUrl=fromQueueUrl, ReceiptHandle=receiptHandle)
And the and example of the DEBUG exception I'm seeing:
[DEBUG] 2020-10-29T21:27:28.32Z 3c60cac9-6d99-58c6-84c9-92dc581919fd retry needed, retryable exception caught:
Connect timeout on endpoint URL: "https://queue.amazonaws.com/" Traceback (most recent call last):
"/var/task/urllib3/connection.py", line 159, in _new_conn conn = connection.create_connection(
File "/var/task/urllib3/util/connection.py", line 84, in create_connection
raise err
File "/var/task/urllib3/util/connection.py", line 74, in create_connection
sock.connect(sa) socket.timeout: timed out During handling of the above exception, another exception occurred: Traceback (most
recent call last):
File "/opt/python/botocore/httpsession.py", line 254, in send
urllib_response = conn.urlopen(
File "/var/task/urllib3/connectionpool.py", line 726, in urlopen
retries = retries.increment(
File "/var/task/urllib3/util/retry.py", line 386, in increment
raise six.reraise(type(error), error, _stacktrace)
File "/var/task/urllib3/packages/six.py", line 735, in reraise
raise value
File "/var/task/urllib3/connectionpool.py", line 670, in urlopen
httplib_response = self._make_request(
File "/var/task/urllib3/connectionpool.py", line 381, in _make_request
self._validate_conn(conn)
File "/var/task/urllib3/connectionpool.py", line 978, in _validate_conn
conn.connect()
File "/var/task/urllib3/connection.py", line 309, in connect
conn = self._new_conn()
File "/var/task/urllib3/connection.py", line 164, in _new_conn
raise ConnectTimeoutError( urllib3.exceptions.ConnectTimeoutError: (<botocore.awsrequest.AWSHTTPSConnection object at 0x7f27b56b7460>, 'Connection
to queue.amazonaws.com timed out. (connect timeout=15)') During handling of the above exception, another
exception occurred: Traceback (most recent call last):
File "/opt/python/utils.py", line 79, in preflight_check
fromQueue = sqs_client.get_queue_url(QueueName=fromQueueName)
File "/opt/python/botocore/client.py", line 357, in _api_call
return self._make_api_call(operation_name, kwargs)
File "/opt/python/botocore/client.py", line 662, in _make_api_call
http, parsed_response = self._make_request(
File "/opt/python/botocore/client.py", line 682, in _make_request
return self._endpoint.make_request(operation_model, request_dict)
File "/opt/python/botocore/endpoint.py", line 102, in make_request
return self._send_request(request_dict, operation_model)
File "/opt/python/botocore/endpoint.py", line 136, in _send_request
while self._needs_retry(attempts, operation_model, request_dict,
File "/opt/python/botocore/endpoint.py", line 253, in _needs_retry
responses = self._event_emitter.emit(
File "/opt/python/botocore/hooks.py", line 356, in emit
return self._emitter.emit(aliased_event_name, **kwargs)
File "/opt/python/botocore/hooks.py", line 228, in emit
return self._emit(event_name, kwargs)
File "/opt/python/botocore/hooks.py", line 211, in _emit
response = handler(**kwargs)
File "/opt/python/botocore/retryhandler.py", line 183, in __call__
if self._checker(attempts, response, caught_exception):
File "/opt/python/botocore/retryhandler.py", line 250, in __call__
should_retry = self._should_retry(attempt_number, response,
File "/opt/python/botocore/retryhandler.py", line 277, in _should_retry
return self._checker(attempt_number, response, caught_exception)
File "/opt/python/botocore/retryhandler.py", line 316, in __call__
checker_response = checker(attempt_number, response,
File "/opt/python/botocore/retryhandler.py", line 222, in __call__
return self._check_caught_exception(
File "/opt/python/botocore/retryhandler.py", line 359, in _check_caught_exception
raise caught_exception
File "/opt/python/botocore/endpoint.py", line 200, in _do_get_response
http_response = self._send(request)
File "/opt/python/botocore/endpoint.py", line 269, in _send
return self.http_session.send(request)
File "/opt/python/botocore/httpsession.py", line 287, in send
raise ConnectTimeoutError(endpoint_url=request.url, error=e) botocore.exceptions.ConnectTimeoutError: Connect timeout on endpoint
URL: "https://queue.amazonaws.com/" During handling of the above exception, another exception occurred: Traceback (most recent
call last):
File "/opt/python/botocore/retryhandler.py", line 269, in _should_retry
return self._checker(attempt_number, response, caught_exception)
File "/opt/python/botocore/retryhandler.py", line 316, in __call__
checker_response = checker(attempt_number, response,
File "/opt/python/botocore/retryhandler.py", line 222, in __call__
return self._check_caught_exception(
File "/opt/python/botocore/retryhandler.py", line 359, in _check_caught_exception
raise caught_exception
File "/opt/python/botocore/endpoint.py", line 200, in _do_get_response
http_response = self._send(request)
File "/opt/python/botocore/endpoint.py", line 269, in _send
return self.http_session.send(request)
File "/opt/python/botocore/httpsession.py", line 287, in send
raise ConnectTimeoutError(endpoint_url=request.url, error=e) botocore.exceptions.ConnectTimeoutError:
Connect timeout on endpoint URL: "https://queue.amazonaws.com/"
Based on the comments.
The SQS timeout was caused by the fact that the lambda function was associated with a VPC, and the VPC had no SQS VPC interface endpoint. Without the endpoint or NAT gateway, the function is not enable to connect to SQS.
The solution was to add the VPC interface endpoint for the SQS service.

python requests SSLError with Heroku set up

I running on Heroku and am getting this error SSLError with requests when sending a request out to an API any Ideas? I beielve this is a issue with my cert or the way I make a connection with requests
Here is my code and error, obviously code is just the just the calls used, and shorted up.
Here is URL used in settings.py
//settings.py
KONNEKTIVE_BASE_URL = 'https://api.konnektive.com/'
Here is api integrations class NEWKonnektive that is used in to call GET request from requests
//konnektive.py
from wrapper import Request
import logging
logger = logging.getLogger(__name__)
class NEWKonnektive(Request):
params = {}
def __init__(self):
self.auth_params = {
'loginId': os.getenv("KONNEKTIVE_USERNAME"),
'password': os.getenv("KONNEKTIVE_PASSWORD")
}
def import_click(self, *args, **kwargs):
function_name = currentframe().f_back.f_code.co_name
self.url = settings.KONNEKTIVE_BASE_URL + 'landers/clicks/import'
self.params = {}
page_type = self.set_param_or_none(kwargs, 'pageType', 'page_type', list_var=PAGE_TYPE_LIST)
if page_type is None: return False
ip_address = self.set_param_or_none(kwargs, 'ipAddress', 'ip_address')
user_agent = self.set_param_or_none(kwargs, 'userAgent', 'user_agent')
campaign_id = self.set_param_or_none(kwargs, 'campaignId', 'campaign_id')
request_uri = self.set_param_or_none(kwargs, 'requestUri', 'request_uri')
session_id = self.set_param_or_none(kwargs, 'sessionId', 'session_id')
if not session_id and (not (ip_address and campaign_id and request_uri)):
logger.error("Konnektive {}: session_id={}, ip_address={}, campaign_id={}, request_uri={}".format(function_name, session_id, ip_address, campaign_id, request_uri))
return False
response = self.get(params=self.params)
logger.info("Konnektive Import Click Response: {}".format(response))
return response
Here is api integrations class NEWKonnektive that is used in to call GET request from requests
// request wrapper.py
import json
import requests
import logging
logger = logging.getLogger(__name__)
HEADERS = {'Content-type': 'application/json'} # Default headers
class Request:
def get(self, params=None):
if not self.auth_params or not self.url:
return
if not params:
params = {}
params.update(self.auth_params)
response = requests.get(self.url, params=params, headers=HEADERS)
logger.info('response url: {}'.format(self.url))
logger.info('response: {}'.format(response))
logger.info('response.ok: {}'.format(response.ok))
logger.info('response.content: {}'.format(response.content))
logger.info('response.header: {}'.format(response.headers))
logger.info('response.url: {}'.format(response.url))
return response.content
current error appearing in New Relic:
// Error logs
Error message
requests.exceptions:SSLError: HTTPSConnectionPool(host='api.konnektive.com', port=443): Max retries exceeded with url: /landers/clicks/import?pageType=leadPage&ipAddress=73.160.94.162&campaignId=1&requestUri=https%3A%2F%2Fwww.workoutwarriors.com%2Fcontact%2F&loginId=**********&password=********** (Caused by SSLError(SSLError("bad handshake: Error([('SSL routines', 'tls_process_server_certificate', 'certificate verify failed')],)",),))
Sample stack trace
Traceback (most recent call last):
File "/app/.heroku/python/bin/gunicorn", line 11, in <module>
File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/app/wsgiapp.py", line 74, in run
File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/app/base.py", line 203, in run
File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/app/base.py", line 72, in run
File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/arbiter.py", line 202, in run
File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/arbiter.py", line 544, in manage_workers
File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/arbiter.py", line 611, in spawn_workers
File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/arbiter.py", line 578, in spawn_worker
File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/workers/base.py", line 131, in init_process
File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/workers/sync.py", line 124, in run
File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/workers/sync.py", line 68, in run_for_one
File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/workers/sync.py", line 30, in accept
File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/workers/sync.py", line 135, in handle
File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/workers/sync.py", line 176, in handle_request
File "/app/.heroku/python/lib/python3.6/site-packages/newrelic/api/web_transaction.py", line 1280, in _nr_wsgi_application_wrapper_
File "/app/.heroku/python/lib/python3.6/site-packages/newrelic/api/web_transaction.py", line 807, in __init__
File "/app/.heroku/python/lib/python3.6/site-packages/newrelic/api/web_transaction.py", line 1169, in _nr_wsgi_application_wrapper_
File "/app/.heroku/python/lib/python3.6/site-packages/django/core/handlers/wsgi.py", line 177, in __call__
File "/app/.heroku/python/lib/python3.6/site-packages/newrelic/hooks/framework_django.py", line 423, in _nr_wrapper_BaseHandler_get_response_
File "/app/.heroku/python/lib/python3.6/site-packages/django/core/handlers/base.py", line 123, in get_response
File "/app/.heroku/python/lib/python3.6/site-packages/newrelic/hooks/framework_django.py", line 220, in wrapper
File "/app/wow/middleware/tracking.py", line 35, in process_request
File "/app/wow/middleware/tracking.py", line 64, in set_url_parameters_in_session
File "/app/integrations/konnektive.py", line 1100, in konnektive_import_click
File "/app/integrations/konnektive.py", line 298, in import_click
File "/app/integrations/wrapper.py", line 17, in get
File "/app/.heroku/python/lib/python3.6/site-packages/requests/api.py", line 72, in get
File "/app/.heroku/python/lib/python3.6/site-packages/newrelic/api/external_trace.py", line 61, in dynamic_wrapper
File "/app/.heroku/python/lib/python3.6/site-packages/newrelic/api/coroutine_trace.py", line 171, in return_value
File "/app/.heroku/python/lib/python3.6/site-packages/newrelic/api/external_trace.py", line 61, in <lambda>
File "/app/.heroku/python/lib/python3.6/site-packages/requests/api.py", line 58, in request
File "/app/.heroku/python/lib/python3.6/site-packages/requests/sessions.py", line 508, in request
File "/app/.heroku/python/lib/python3.6/site-packages/newrelic/api/external_trace.py", line 61, in dynamic_wrapper
File "/app/.heroku/python/lib/python3.6/site-packages/newrelic/api/coroutine_trace.py", line 171, in return_value
File "/app/.heroku/python/lib/python3.6/site-packages/newrelic/api/external_trace.py", line 61, in <lambda>
File "/app/.heroku/python/lib/python3.6/site-packages/requests/sessions.py", line 618, in send
File "/app/.heroku/python/lib/python3.6/site-packages/requests/adapters.py", line 506, in send
My cert isn't invalid right? I am using the default ACM cert Heroku gives out if you are using a custom domain.
SSLError("bad handshake: Error([('SSL routines', 'tls_process_server_certificate', 'certificate verify failed')],)")
this is how i checked:
openssl s_client -connect “workoutwarriors.com:443” -showcerts -servername “workoutwarriors.com”

Add proxy credential to google-calendar connection

Im trying to get event from google calendar by python, Im using google quickstart example, I get browser opening to confirm credential but on my pc I get following error:
Traceback (most recent call last):
File "C:\Programs\Python\Python35-32\lib\site-packages\httplib2\__init__.py", line 987, in _conn_request
conn.connect()
File "C:\Programs\Python\Python35-32\lib\http\client.py", line 1252, in connect
super().connect()
File "C:\Programs\Python\Python35-32\lib\http\client.py", line 849, in connect
(self.host,self.port), self.timeout, self.source_address)
File "C:\Programs\Python\Python35-32\lib\socket.py", line 693, in create_connection
for res in getaddrinfo(host, port, 0, SOCK_STREAM):
File "C:\Programs\Python\Python35-32\lib\socket.py", line 732, in getaddrinfo
for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno 11002] getaddrinfo failed
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\myUser\Documents\Python_projects\quickstart.py", line 79, in <module>
main()
File "C:\Users\myUser\Documents\Python_projects\quickstart.py", line 60, in main
credentials = get_credentials()
File "C:\Users\myUser\Documents\Python_projects\quickstart.py", line 48, in get_credentials
credentials = tools.run_flow(flow, store, flags)
File "C:\Programs\Python\Python35-32\lib\site-packages\oauth2client\util.py", line 137, in positional_wrapper
return wrapped(*args, **kwargs)
File "C:\Programs\Python\Python35-32\lib\site-packages\oauth2client\tools.py", line 243, in run_flow
credential = flow.step2_exchange(code, http=http)
File "C:\Programs\Python\Python35-32\lib\site-packages\oauth2client\util.py", line 137, in positional_wrapper
return wrapped(*args, **kwargs)
File "C:\Programs\Python\Python35-32\lib\site-packages\oauth2client\client.py", line 2027, in step2_exchange
headers=headers)
File "C:\Programs\Python\Python35-32\lib\site-packages\httplib2\__init__.py", line 1314, in request
(response, content) = self._request(conn, authority, uri, request_uri, method, body, headers, redirections, cachekey)
File "C:\Programs\Python\Python35-32\lib\site-packages\httplib2\__init__.py", line 1064, in _request
(response, content) = self._conn_request(conn, request_uri, method, body, headers)
File "C:\Programs\Python\Python35-32\lib\site-packages\httplib2\__init__.py", line 994, in _conn_request
raise ServerNotFoundError("Unable to find the server at %s" % conn.host)
httplib2.ServerNotFoundError: Unable to find the server at accounts.google.com
I suppose the problem is due to my proxy but where can I set proxy setting?
Thanks in advance

Resources