question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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,
#            )

Issue Analytics

  • State:open
  • Created 5 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

4reactions
dmyerscoughcommented, Dec 21, 2018

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

Getting "OSError: [Errno 0] Error" when using either requests ...
Firstly, requests 2.24 requires urllib3 < 1.26 and in urllib3 1.25 , the wrap_socket call was not from a SSLContext ; this seemed...
Read more >
SSLContext.wrap_socket() throws OSError with errno == 0
Python and/or Open SSL correctly treats this as an error, but then assumes “errno” is valid. Perhaps Python should be raising SSLEOFError in ......
Read more >
How to troubleshoot RubyGems and Bundler TLS/SSL Issues
To troubleshoot protocol connection errors, start by running the automatic SSL check, and follow the instructions. You might need to update Bundler, update ......
Read more >
How to troubleshoot subscription-manager and yum issues
Check if a proxy (or anything between the server and Red Hat) is not changing the SSL certificate. · When using a http...
Read more >
Use Python-API behind Proxy - Page 3 - Esri Community
Our company runs it's own public key infrastructure, so I've configured ... so you end up with proxy errors in the request because...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found