Skip to content
This repository has been archived by the owner on Oct 23, 2023. It is now read-only.

SSL OSError: [Errno 0] Error when running behind a proxy #1285

Open
dmyerscough opened this issue Aug 12, 2018 · 5 comments
Open

SSL OSError: [Errno 0] Error when running behind a proxy #1285

dmyerscough opened this issue Aug 12, 2018 · 5 comments

Comments

@dmyerscough
Copy link

dmyerscough commented Aug 12, 2018

I have been using Sentry for a Django application that runs behind Istio Service Mesh. When I run the sample exception snippet I get the following exception:-

./manage.py shell --settings=mirussh.settings.staging
Python 3.6.5 (default, Jun 27 2018, 08:18:52) 
[GCC 6.3.0 20170516] on linux
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> from raven.contrib.django.raven_compat.models import client
>>> 
>>> client.captureException()

Traceback (most recent call last):
  File "/usr/local/lib/python3.6/code.py", line 91, in runcode
    exec(code, self.locals)
  File "<console>", line 1, in <module>
  File "/usr/local/lib/python3.6/site-packages/raven/base.py", line 824, in captureException
    'raven.events.Exception', exc_info=exc_info, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/raven/contrib/django/client.py", line 303, in capture
    result = super(DjangoClient, self).capture(event_type, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/raven/base.py", line 635, in capture
    elif not self.should_capture(exc_info):
  File "/usr/local/lib/python3.6/site-packages/raven/base.py", line 828, in should_capture
    exc_name = '%s.%s' % (exc_type.__module__, exc_type.__name__)
AttributeError: 'NoneType' object has no attribute '__module__'
>>> 
2018-08-11 08:05:39,009 sentry.errors ERROR    Sentry responded with an error: <urlopen error [Errno 0] Error> (url: https://sentry.io/api/1231405/store/)
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/urllib/request.py", line 1318, in do_open
    encode_chunked=req.has_header('Transfer-encoding'))
  File "/usr/local/lib/python3.6/http/client.py", line 1239, in request
    self._send_request(method, url, body, headers, encode_chunked)
  File "/usr/local/lib/python3.6/http/client.py", line 1285, in _send_request
    self.endheaders(body, encode_chunked=encode_chunked)
  File "/usr/local/lib/python3.6/http/client.py", line 1234, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
  File "/usr/local/lib/python3.6/http/client.py", line 1026, in _send_output
    self.send(msg)
  File "/usr/local/lib/python3.6/http/client.py", line 964, in send
    self.connect()
  File "/usr/local/lib/python3.6/site-packages/raven/utils/http.py", line 39, in connect
    sock, ca_certs=ca_certs, cert_reqs=ssl.CERT_REQUIRED)
  File "/usr/local/lib/python3.6/ssl.py", line 1149, in wrap_socket
    ciphers=ciphers)
  File "/usr/local/lib/python3.6/ssl.py", line 814, in __init__
    self.do_handshake()
  File "/usr/local/lib/python3.6/ssl.py", line 1068, in do_handshake
    self._sslobj.do_handshake()
  File "/usr/local/lib/python3.6/ssl.py", line 689, in do_handshake
    self._sslobj.do_handshake()
OSError: [Errno 0] Error

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/raven/transport/threaded.py", line 165, in send_sync
    super(ThreadedHTTPTransport, self).send(url, data, headers)
  File "/usr/local/lib/python3.6/site-packages/raven/transport/http.py", line 43, in send
    ca_certs=self.ca_certs,
  File "/usr/local/lib/python3.6/site-packages/raven/utils/http.py", line 67, in urlopen
    return opener.open(url, data, timeout)
  File "/usr/local/lib/python3.6/urllib/request.py", line 526, in open
    response = self._open(req, data)
  File "/usr/local/lib/python3.6/urllib/request.py", line 544, in _open
    '_open', req)
  File "/usr/local/lib/python3.6/urllib/request.py", line 504, in _call_chain
    result = func(*args)
  File "/usr/local/lib/python3.6/site-packages/raven/utils/http.py", line 47, in https_open
    return self.do_open(ValidHTTPSConnection, req)
  File "/usr/local/lib/python3.6/urllib/request.py", line 1320, in do_open
    raise URLError(err)
urllib.error.URLError: <urlopen error [Errno 0] Error>
b'Sentry responded with an error: <urlopen error [Errno 0] Error> (url: https://sentry.io/api/1231405/store/)'
2018-08-11 08:05:39,011 sentry.errors.uncaught ERROR    ["AttributeError: 'NoneType' object has no attribute '__module__'", '  File "python3.6/code.py", line 91, in runcode', '  File "<console>", line 1, in <module>', '  File "raven/base.py", line 824, in captureException', '  File "raven/contrib/django/client.py", line 303, in capture', '  File "raven/base.py", line 635, in capture', '  File "raven/base.py", line 828, in should_capture']
b'["AttributeError: \'NoneType\' object has no attribute \'__module__\'", \'  File "python3.6/code.py", line 91, in runcode\', \'  File "<console>", line 1, in <module>\', \'  File "raven/base.py", line 824, in captureException\', \'  File "raven/contrib/django/client.py", line 303, in capture\', \'  File "raven/base.py", line 635, in capture\', \'  File "raven/base.py", line 828, in should_capture\']'

I modified the raven/transport/http.py to use requests instead and the exception went away:-

    def send(self, url, data, headers):
        """
        Sends a request to a remote webserver using HTTP POST.
        """
        # req = urllib2.Request(url, headers=headers)

        try:
            response = requests.post(
                url=url,
                data=data,
                timeout=self.timeout,
                verify=self.verify_ssl,
                headers=headers,
                certs=self.ca_certs,
            )
#            response = urlopen(
#                url=req,
#                data=data,
#                timeout=self.timeout,
#                verify_ssl=self.verify_ssl,
#                ca_certs=self.ca_certs,
#            )
@hamzdiou
Copy link

Hi @dmyerscough !

I've the same issue, maybe because of HTTP_PROXY as discussed here : https://github.com/getsentry/raven-python/issues/338.

Seems that your solution work but how to overwrite the send method without writting directly on the http.py file ? How to get it work so that next time we deploy it and install raven through pip, all works good ?

Thanks !

@dmyerscough
Copy link
Author

I forked python-raven as I was getting no traction. Anyone using Istio/Envoy will bump into this issue.

@untitaker
Copy link
Member

If you mean to use requests instead of urllib, you can configure a different transport. No need to fork

@untitaker
Copy link
Member

@dmyerscough
Copy link
Author

Interesting, let me give this a try. Ill configure a test environment this evening and let you know the outcome.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants