Amertz08 / drf_ujson2

JSON parser and renderer using ujson for Django Rest Framework
MIT License
36 stars 4 forks source link

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

Open pasevin opened 4 years ago

pasevin commented 4 years ago

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

Amertz08 commented 4 years ago

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.

double-di commented 4 years ago

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

pasevin commented 4 years ago

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

Amertz08 commented 4 years ago

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 commented 3 years ago

@pasevin are you still having this issue?

pasevin commented 3 years ago

@pasevin are you still having this issue?

Yes, it's still happening, unfortunately.