drf_ujson2 icon indicating copy to clipboard operation
drf_ujson2 copied to clipboard

Issue with django-rest-auth and dj-rest-auth libraries

Open pasevin opened this issue 4 years ago • 6 comments

Not sure why, but can't use this library together with https://github.com/Tivix/django-rest-auth or later fork https://github.com/jazzband/dj-rest-auth. Keep getting errors of this type for all responses: TypeError: 'Password has been reset with the new password.' is not JSON serializable

pasevin avatar Aug 22 '20 14:08 pasevin

I'll have to look through this more in depth. Thank you for bringing it to my attention. My guess here is that at some point that string literally ("Password has been reset with a new password.") is being passed into the renderer. Why that is happening is what we'd need to dig into.

Amertz08 avatar Aug 23 '20 19:08 Amertz08

Yes, having same problem, but with /logout method. 'Успешно вышли.' is not JSON serializable. I think it has something to do with utf8 serialization

double-di avatar Sep 14 '20 10:09 double-di

@double-di for now my solution was just to subclass the view which is failing and set renderer_classes = [JSONRenderer]

pasevin avatar Sep 16 '20 10:09 pasevin

What is the data parameter in the render coming through as? The error seems to indicate it is a string. However that should work with ujson.dumps

>>> import ujson
>>> ujson.dumps("a")
'"a"'
>>> ujson.dumps(b"a")
'"a"'
>>> import json
>>> ujson.dumps("a".encode())
'"a"'
>>> json.dumps("a")
'"a"'
>>> json.dumps(b"a")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/adammertz/.pyenv/versions/3.6.6/lib/python3.6/json/__init__.py", line 231, in dumps
    return _default_encoder.encode(obj)
  File "/Users/adammertz/.pyenv/versions/3.6.6/lib/python3.6/json/encoder.py", line 199, in encode
    chunks = self.iterencode(o, _one_shot=True)
  File "/Users/adammertz/.pyenv/versions/3.6.6/lib/python3.6/json/encoder.py", line 257, in iterencode
    return _iterencode(o, 0)
  File "/Users/adammertz/.pyenv/versions/3.6.6/lib/python3.6/json/encoder.py", line 180, in default
    o.__class__.__name__)
TypeError: Object of type 'bytes' is not JSON serializable
>>> json.dumps("a".encode())
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/adammertz/.pyenv/versions/3.6.6/lib/python3.6/json/__init__.py", line 231, in dumps
    return _default_encoder.encode(obj)
  File "/Users/adammertz/.pyenv/versions/3.6.6/lib/python3.6/json/encoder.py", line 199, in encode
    chunks = self.iterencode(o, _one_shot=True)
  File "/Users/adammertz/.pyenv/versions/3.6.6/lib/python3.6/json/encoder.py", line 257, in iterencode
    return _iterencode(o, 0)
  File "/Users/adammertz/.pyenv/versions/3.6.6/lib/python3.6/json/encoder.py", line 180, in default
    o.__class__.__name__)
TypeError: Object of type 'bytes' is not JSON serializable

Amertz08 avatar Sep 16 '20 15:09 Amertz08

@pasevin are you still having this issue?

Amertz08 avatar May 02 '21 16:05 Amertz08

@pasevin are you still having this issue?

Yes, it's still happening, unfortunately.

pasevin avatar Sep 21 '21 07:09 pasevin