4

I want to add a test sentry instance that has a self signed certificate.

The app has the default RAVEN_CONFIG

RAVEN_CONFIG = {
    'dsn': 'https://xxxx@sentry.tst2.server.com/2',
    # If you are using git, you can also automatically configure the
    # release based on the git info.
    'release': raven.fetch_git_sha(os.path.dirname(os.pardir)),
}

I tried to add 'verify_ssl':0 to the configuration dictionary to no avail.

This is the error I'm getting:

Traceback (most recent call last):
  File "/opt/apps/.virtualenvs/palantir/local/lib/python2.7/site-packages/raven/transport/threaded.py", line 162, in send_sync
    super(ThreadedHTTPTransport, self).send(data, headers)
  File "/opt/apps/.virtualenvs/palantir/local/lib/python2.7/site-packages/raven/transport/http.py", line 47, in send
    ca_certs=self.ca_certs,
  File "/opt/apps/.virtualenvs/palantir/local/lib/python2.7/site-packages/raven/utils/http.py", line 62, in urlopen
    return opener.open(url, data, timeout)
  File "/usr/lib/python2.7/urllib2.py", line 431, in open
    response = self._open(req, data)
  File "/usr/lib/python2.7/urllib2.py", line 449, in _open
    '_open', req)
  File "/usr/lib/python2.7/urllib2.py", line 409, in _call_chain
    result = func(*args)
  File "/opt/apps/.virtualenvs/palantir/local/lib/python2.7/site-packages/raven/utils/http.py", line 46, in https_open
    return self.do_open(ValidHTTPSConnection, req)
  File "/usr/lib/python2.7/urllib2.py", line 1197, in do_open
    raise URLError(err)
URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:581)>
windravenii
  • 95
  • 1
  • 9

4 Answers4

12

Can you try adding verify_ssl=0 to your DSN as shown the docs:

https://xxxx@sentry.tst2.server.com/2?verify_ssl=0
tayfun
  • 3,065
  • 1
  • 19
  • 23
  • Turns out it happened because of an old raven version. `pip install --upgrade raven` and `?verify_ssl=0` did the trick. Thanks a lot :D – windravenii Oct 06 '17 at 21:52
3

overwrite sentry-python's function

def disable_sentry_ssl_check():
    # disable sni warnings
    import urllib3
    urllib3.disable_warnings()

    def _get_pool_options(self, ca_certs):
        return {
            "num_pools": 2,
            "cert_reqs": "CERT_NONE",
        }

    # disable ssl check
    from sentry_sdk.transport import HttpTransport
    HttpTransport._get_pool_options = _get_pool_options
Color
  • 875
  • 9
  • 11
1

Put below code in settings.py:

# Sentry
# https://docs.sentry.io/platforms/python/guides/django/

def _get_pool_options(self, ca_certs):
    return {
        'num_pools': 2,
        'cert_reqs': 'CERT_NONE'
    }

if sentry_dsn := os.getenv('SENTRY_DSN'):
    sentry_sdk.transport.HttpTransport._get_pool_options = _get_pool_options
    sentry_sdk.init(dsn=sentry_dsn, integrations=[DjangoIntegration()], send_default_pii=True)

requirements.txt file:

Django==3.1.1
sentry-sdk==0.19.4
Bruno Wego
  • 2,099
  • 3
  • 21
  • 38
0

This worked for me:

from raven.transport.requests import RequestsHTTPTransport
RAVEN_CONFIG = {
'transport': RequestsHTTPTransport, 
'dsn': DSN 
}

Note: It calls synchronously.

Husain Basrawala
  • 1,757
  • 15
  • 21