I am setting up Sentry for my Flask/Lambda and I am receiving the following tracebacks in my Zappa (Flask/Lambda) logs:
Sentry responded with an error: <urlopen error [Errno 1] Operation not permitted> (url: https://sentry.io/api/XXXXXX/store/)
Traceback (most recent call last):
File "/var/lang/lib/python3.6/urllib/request.py", line 1318, in do_open
encode_chunked=req.has_header('Transfer-encoding'))
File "/var/lang/lib/python3.6/http/client.py", line 1239, in request
self._send_request(method, url, body, headers, encode_chunked)
File "/var/lang/lib/python3.6/http/client.py", line 1285, in _send_request
self.endheaders(body, encode_chunked=encode_chunked)
File "/var/lang/lib/python3.6/http/client.py", line 1234, in endheaders
self._send_output(message_body, encode_chunked=encode_chunked)
File "/var/lang/lib/python3.6/http/client.py", line 1026, in _send_output
self.send(msg)
File "/var/lang/lib/python3.6/http/client.py", line 964, in send
self.connect()
File "/var/task/raven/utils/http.py", line 31, in connect
timeout=self.timeout,
File "/var/lang/lib/python3.6/socket.py", line 722, in create_connection
raise err
File "/var/lang/lib/python3.6/socket.py", line 713, in create_connection
sock.connect(sa)
PermissionError: [Errno 1] Operation not permitted
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/var/task/raven/transport/threaded.py", line 165, in send_sync
super(ThreadedHTTPTransport, self).send(url, data, headers)
File "/var/task/raven/transport/http.py", line 43, in send
ca_certs=self.ca_certs,
File "/var/task/raven/utils/http.py", line 66, in urlopen
return opener.open(url, data, timeout)
File "/var/lang/lib/python3.6/urllib/request.py", line 526, in open
response = self._open(req, data)
File "/var/lang/lib/python3.6/urllib/request.py", line 544, in _open
'_open', req)
File "/var/lang/lib/python3.6/urllib/request.py", line 504, in _call_chain
result = func(*args)
File "/var/task/raven/utils/http.py", line 46, in https_open
return self.do_open(ValidHTTPSConnection, req)
File "/var/lang/lib/python3.6/urllib/request.py", line 1320, in do_open
raise URLError(err)
urllib.error.URLError: <urlopen error [Errno 1] Operation not permitted>
Sentry is configured as follows:
# app/__init__.py
from raven.contrib.awslambda import LambdaClient
from raven.contrib.flask import Sentry
import logging
sentry = Sentry()
sentry_lambda_client = LambdaClient()
log = logging.getLogger(__name__)
@sentry_lambda_client.capture_exceptions
def exception_handler(e, event, context):
sentry_lambda_client.captureException(event=event, context=context)
return True
def create_app(app_stage):
APP_PATH = os.path.dirname(os.path.abspath(__file__))
STATIC_PATH = os.path.join(APP_PATH, 'static/')
app = Flask(__name__, instance_relative_config=True,
static_folder=STATIC_PATH, static_url_path='/static')
app.config.from_object(app_config[app_stage])
app.config.from_pyfile('config.py')
app.config['SENTRY_CONFIG'] = {'include_paths': ['app.auth', 'app.imports']}
sentry.init_app(app, logging=True, level=logging.DEBUG)
# zappa_settings.json
{
“dev”: {
“app_function”: “run.app”,
“aws_region”: “ap-southeast-2”,
“exception_handler”: “app.exception_handler”,
“exclude”: [“pycache”, “*.pyc”, “images”, “js”, “node_modules”],
“profile_name”: “default”,
“project_name”: “pythagoras-app”,
“runtime”: “python3.6”,
“s3_bucket”: “zappa-pythagoras-dev”
}
}