'encoding' cannot be specified in python 3
See original GitHub issueThe ‘json.dumps’ command no longer have an encoding argument in python 3 and causes this stacktrace:
File "/usr/local/lib/python3.6/site-packages/raven/handlers/logging.py", line 89, in emit
return self.emit(record)
File "/usr/local/lib/python3.6/site-packages/raven/handlers/logging.py", line 182, in _emit
*kwargs)
File "/usr/local/lib/python3.6/site-packages/raven/base.py", line 645, in capture
self.send(*data)
File "/usr/local/lib/python3.6/site-packages/raven/base.py", line 740, in send
message = self.encode(data)
File "/usr/local/lib/python3.6/site-packages/raven/base.py", line 782, in encode
return zlib.compress(json.dumps(data).encode('utf8'))
File "/usr/local/lib/python3.6/site-packages/raven/utils/json.py", line 51, in dumps
return json.dumps(value, cls=BetterJSONEncoder, **kwargs)
File "/usr/local/lib/python3.6/json/init.py", line 238, in dumps
**kw).encode(obj)
TypeError: __init_() got an unexpected keyword argument 'encoding'
Issue Analytics
- State:
- Created 6 years ago
- Reactions:2
- Comments:12 (4 by maintainers)
Top Results From Across the Web
Python 3 character encoding issue - Stack Overflow
My issue relates to using a jinja2 template. Where the template doesn't contain any unicode everything is OK, however, once there is a...
Read more >Python String encode() Method - W3Schools
The encode() method encodes the string, using the specified encoding. ... These examples uses ascii encoding, and a character that cannot be encoded, ......
Read more >Unicode HOWTO — Python 3.11.1 documentation
Encodings are specified as strings containing the encoding's name. Python comes with roughly 100 different encodings; see the Python Library Reference at ...
Read more >Unicode & Character Encodings in Python: A Painless Guide
Encoding and Decoding in Python 3 ... Python 3's str type is meant to represent human-readable text and can contain any Unicode character....
Read more >Python 3 Notes: Reading and Writing Methods
"UnicodeDecodeError" means you have a file encoding issue. Each computer has its own system-wide default encoding, and the file you are trying to...
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
I don’t think this should be closed.
I am seeing this still, and it’s a bit confusing, but here is what is happening. We have this code in Sentry:
https://github.com/getsentry/raven-python/blob/1a0d697dd11459bfa8ce933b3b53264098dad60d/raven/utils/json.py#L46-L51
The logic here seems to be: Try to serialize everything to JSON, and if that fails for any reason, try it again, but this time use a special codec that ignores any errors. (Question: Why use a catch-all here, rather than just catching encoding-related exceptions?).
The problem, as stated above, is that on Python 3, the
encoding
argument is no longer supported. So if for any reason this fallback-branch triggers, we get an exception like this:So the task here would probably to a) find a way to support the fallback-branch on Python 3, or disable the fallback branch on Py3 so the exception is less confusing.
Thank you for the information. What I am using is the latest released version 6.10.0. It doesn’t include the fix. I think Sentry stops continuing on this package as they didn’t release new version on PYPI for about two years. I moved to the
sentry_sdk
package instead.