`Client.captureException(None)` results in a `UnicodeDecodeError` with python 2.7 if future library is used
See original GitHub issueThis is happening on python 2.7.9 with raven 5.23.0. Full traceback from the sending thread is below:
Traceback (most recent call last):
File "/home/russ/.virtualenvs/edms/lib/python2.7/site-packages/raven/transport/threaded.py", line 174, in send_sync
super(ThreadedHTTPTransport, self).send(data, headers)
File "/home/russ/.virtualenvs/edms/lib/python2.7/site-packages/raven/transport/http.py", line 47, in send
ca_certs=self.ca_certs,
File "/home/russ/.virtualenvs/edms/lib/python2.7/site-packages/raven/utils/http.py", line 66, in urlopen
return opener.open(url, data, timeout)
File "/home/russ/.virtualenvs/edms/lib/python2.7/site-packages/future/backports/urllib/request.py", line 494, in open
response = self._open(req, data)
File "/home/russ/.virtualenvs/edms/lib/python2.7/site-packages/future/backports/urllib/request.py", line 512, in _open
'_open', req)
File "/home/russ/.virtualenvs/edms/lib/python2.7/site-packages/future/backports/urllib/request.py", line 466, in _call_chain
result = func(*args)
File "/home/russ/.virtualenvs/edms/lib/python2.7/site-packages/raven/utils/http.py", line 46, in https_open
return self.do_open(ValidHTTPSConnection, req)
File "/home/russ/.virtualenvs/edms/lib/python2.7/site-packages/future/backports/urllib/request.py", line 1284, in do_open
h.request(req.get_method(), req.selector, req.data, headers)
File "/opt/python2.7.9/lib/python2.7/httplib.py", line 1001, in request
self._send_request(method, url, body, headers)
File "/opt/python2.7.9/lib/python2.7/httplib.py", line 1035, in _send_request
self.endheaders(body)
File "/opt/python2.7.9/lib/python2.7/httplib.py", line 997, in endheaders
self._send_output(message_body)
File "/opt/python2.7.9/lib/python2.7/httplib.py", line 848, in _send_output
msg += message_body
UnicodeDecodeError: 'ascii' codec can't decode byte 0x9c in position 1: ordinal not in range(128)
Note the future
module in there… suspicious?
For the failed capture, here is some debug info on what is being sent to the raven Client’s transport.async_send
:
>>> type(data), data[:10], headers
(<type 'str'>,
'x\x9c\xed]\x0bw\xe2F\xb2\xfe',
{'Content-Encoding': 'deflate',
'Content-Type': 'application/octet-stream',
'User-Agent': 'raven-python/5.23.0',
'X-Sentry-Auth': 'Sentry sentry_timestamp=1468702548.44, sentry_client=raven-python/5.23.0, sentry_version=6, sentry_key=3de74049829c4e22827b100a5ece12e1, sentry_secret=<too secret to include>'})
At the httplib
exception location (msg += message_body
) in the thread, we end up with str
and unicode
, and the zlib-compressed str block:
>>> type(msg), type(message_body), message_body[:10]
(<type 'unicode'>, <type 'str'>, 'x\x9c\xed]\x0bw\xe2F\xb2\xfe')
Also potentially of note is that self._buffer
that got joined prior to the exception line was a mixed bag of str
and unicode
:
>>> map(type, self._buffer)
[<type 'unicode'>,
<type 'str'>,
<type 'unicode'>,
<type 'str'>,
<type 'unicode'>,
<type 'str'>,
<type 'str'>,
<type 'unicode'>,
<type 'str'>]
>>> self._buffer[:3]
[u'POST /api/4/store/ HTTP/1.1',
'Accept-Encoding: identity',
u'Content-Length: 5476']
Issue Analytics
- State:
- Created 7 years ago
- Reactions:1
- Comments:13 (7 by maintainers)
Top Results From Across the Web
How to fix: "UnicodeDecodeError: 'ascii' codec can't decode ...
If a UnicodeDecodeError from the read() line, then you've probably used the wrong encoding value. CSV Files. The Python 2.7 CSV module does...
Read more >read_hdf throws UnicodeDecodeError with Python 3.5 and 3.6 ...
Problem description. The HDF5 dataset was created with pandas , to_hdf in Python 2.7 and can be read in by Python 2.7. When...
Read more >codecs — Codec registry and base classes — Python 3.11.1 ...
Source code: Lib/codecs.py This module defines base classes for standard Python ... If encoding is not None , then the underlying encoded files...
Read more >Six: Python 2 and 3 Compatibility Library — six 1.15.0 ...
This is unicode() in Python 2 and str in Python 3. Type for representing binary data. This is str in Python 2 and...
Read more >Supporting Python 2 and Python 3 - scikit-bio
Recent versions of the future project stopped bundling the six library, so we also directly depend on six (e.g., for StringIO compatibility).
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Seems to be solved as of https://github.com/getsentry/raven-python/commit/c69abaa1506a426802e979c7f8c6a4ab0ef9c4d7#diff-1009f02b22291a2682b3d868a2211291R190
Specifically, this commit makes it so that
raven.utils.compat.urllib2
is no longerfuture.backports.urllib.request
on Python 2.closing, thanks!