Re: DRF UnicodeDecodeError: 'utf-8' codec can't decode byte 0xf6

2019-11-20 Thread Aldian Fazrihady
I guess texts in your database is encoded using other than UTF-8.

Please change `getline(self.filename, ..)` to
`getline(self.filename.decode('utf-16'), ..`

On Mon, Oct 21, 2019 at 7:48 PM Kerstin Rohm <
kerstin.r...@ibmt.fraunhofer.de> wrote:

> Dear Django Community,
>
>
> we have a curious encoding error and we are running out of ideas to solve
> the problem.
>
> We build a Django REST Service with the following packages:
>
>
>
> dj-database-url 0.5.0
>
> Django 2.2.1
>
> django-filter 2.1.0
>
> django-oauth-toolkit 1.2.0
>
> django-widget-tweaks 1.4.3
>
> djangorestframework 3.9.3
>
> python-decouple 3.1
>
> argon2-cffi 19.1.0
>
> plotly 4.1.1
>
>
> When we call a specific REST function (e.g.
>
> *@api_view*([*'POST'*])
>
> *@permission_classes*([AllowAny])
>
> def *token*(request):
>
> r = requests.post(*'http://127.0.0.1:8000/rest/oauth2/token/
> '*,
>
>   data={*'grant_type'* : *'password'*,
>
> *'username'* : request.data[*'username'*],
>
> *'password'* : request.data[*'password'*],
>
> *'client_id'* : settings.REST_CLIENT_ID,
>
> *'client_secret'* :
> settings.REST_CLIENT_SECRET,},)
>
> return Response(r.json())
>
> )
>
>
> We are getting a UFT8 encoding error (Traceback see below). The content of
> “data” seems to be ok:
>
>
> data= {'grant_type': 'password', 'username': 'x', 'password': 'x',
> 'client_id': 'TQmAHzCM2r9nfkruVQw0eMQ0AziSvLAnf4ufvZ1o', 'client_secret':
> 'GISUGXxa2e4JHejUCImMMUMJMtZ13byvc8fySUvX7shELNLPE5xZBA3p0cvbXvvrPIWgltSkTNZ9a7JHPQswEKHzZEDkl21ekS3T6NefUrzVFsdyRS0A2qOHL1L4Nra5'}
>
>
> We have the same error on our testing LINUX system and our development
> environment on windows. We tried to call the REST function via local
> testing method, Android app and CURL – same behavior.
>
> The settings of UNICODE_JSON = True/False causes no difference.
>
>
> We tried it with a REST function without OAUTH Token creation (username
> and password credentials) – same behavior.
>
>
> But – when we call the function with the arguments REST_CLIENT_ID and
> REST_CLIENT_SECRET the function is working fine:
>
> curl -X POST -d 
> "grant_type=password=emilia.muel...@email.com=qwertzui"
> -u"VAOpqwqOTl99jRVXY63Bv5uNXs2MpJWUlZSwSZBf:cgrDaIjPyAy45Z1yxarT0iP9UOjw7gvbpnMirgwz24A56EeJGONHYSsqs9eVPHAyLrsPZdwfdQxoGPnM4LFtihltxlrX24hCQIIE57JezwSHIJab9VjTwAjS9LxYFVJm"
> "127.0.0.1:8000/rest/oauth2/token/"
>
> response: {"access_token": "Fz7yTNSsdUxRaWuMj4Sf4OnPe0Ujf6", "expires_in":
> 3000, "token_type": "Bearer", "scope": "read write", "refresh_token":
> "r9H5E8MK5AAy57ZdiFUJaWaJT63kJL"}
>
>
> But – when we tried to call the other functions with this token and are 
> getting the same encoding error (traceback below):
>
>
>
> curl -X GET -H "Authorization: Bearer Fz7yTNSsdUxRaWuMj4Sf4OnPe0Ujf6"
> 127.0.0.1:8000/rest/patient/1
>
> Everything worked fine a few weeks ago, but after a database change the
> problem occurs. Setting the DB Model to the previous entries was not
> successful.
>
>
> It would be really great if some of you would have any idea what is
> working wrong here!
>
> Thanks in advance!
>
>
> Kerstin and Romy
>
>
> ---
> Traceback
>
>
> Traceback (most recent call last):
>   File "C:\Python37\lib\site-packages\django\core\handlers\exception.py", 
> line 34, in inner
> response = get_response(request)
>   File "C:\Python37\lib\site-packages\django\core\handlers\base.py", line 
> 115, in _get_response
> response = self.process_exception_by_middleware(e, request)
>   File "C:\Python37\lib\site-packages\django\core\handlers\base.py", line 
> 113, in _get_response
> response = wrapped_callback(request, *callback_args, **callback_kwargs)
>   File "C:\Python37\lib\site-packages\django\views\decorators\csrf.py", line 
> 54, in wrapped_view
> return view_func(*args, **kwargs)
>   File "C:\Python37\lib\site-packages\django\views\generic\base.py", line 71, 
> in view
> return self.dispatch(request, *args, **kwargs)
>   File "C:\Python37\lib\site-packages\rest_framework\views.py", line 495, in 
> dispatch
> response = self.handle_exception(exc)
>   File "C:\Python37\lib\site-packages\rest_framework\views.py", line 455, in 
> handle_exception
> self.raise_uncaught_exception(exc)
>   File "C:\Python37\lib\site-packages\rest_framework\views.py", line 492, in 
> dispatch
> response = handler(request, *args, **kwargs)
>   File "C:\Users\andresr\InsisT\Server\insist_rest\views.py", line 93, in get
> return Response(self.serializer_class(patient[0]).data, 
> status=status.HTTP_200_OK)
>   File "C:\Python37\lib\site-packages\rest_framework\response.py", line 32, 
> in __init__
> super(Response, self).__init__(None, status=status)
>   File "C:\Python37\lib\site-packages\django\template\response.py", line 36, 
> in __init__
> super().__init__('', content_type, status, charset=charset)
>  

Re: DRF UnicodeDecodeError: 'utf-8' codec can't decode byte 0xf6

2019-11-20 Thread Sarah Werker
On Monday, October 21, 2019 at 8:49:02 AM UTC-4, Kerstin Rohm wrote:
> Dear Django Community,
> 
> I think you should call me at 574-217-1330 or text and we can discuss it
> 
> 
> we have a curious encoding error and we are running out of ideas to
> solve the problem.
> 
> 
> We build a Django REST Service with the following packages: 
> 
> 
>  
> 
> 
> dj-database-url 0.5.0
> 
> 
> Django 2.2.1
> 
> 
> django-filter 2.1.0
> 
> 
> django-oauth-toolkit 1.2.0
> 
> 
> django-widget-tweaks 1.4.3
> 
> 
> djangorestframework 3.9.3
> 
> 
> python-decouple 3.1
> 
> 
> argon2-cffi 19.1.0
> 
> 
> plotly 4.1.1
> 
> 
> 
> 
> When we call a specific REST function (e.g.
> 
> 
> @api_view(['POST'])
> 
> 
> @permission_classes([AllowAny])
> 
> 
> def token(request):
> 
> 
>    
> r = requests.post('http://127.0.0.1:8000/rest/oauth2/token/',
> 
> 
>   data={'grant_type' : 'password',
> 
> 
>     'username' : request.data['username'],
> 
> 
>     'password' : request.data['password'],
> 
> 
>     'client_id' :
> settings.REST_CLIENT_ID,
> 
> 
>     'client_secret' :
> settings.REST_CLIENT_SECRET,},)
> 
> 
>     return
> Response(r.json())
> 
> 
> )
> 
> 
> 
> 
> We are getting a UFT8 encoding error (Traceback see below).
> The content of “data” seems to be ok:
> 
> 
> 
> 
> data=
> {'grant_type': 'password', 'username': 'x', 'password': 'x', 'client_id':
> 'TQmAHzCM2r9nfkruVQw0eMQ0AziSvLAnf4ufvZ1o', 'client_secret':
> 'GISUGXxa2e4JHejUCImMMUMJMtZ13byvc8fySUvX7shELNLPE5xZBA3p0cvbXvvrPIWgltSkTNZ9a7JHPQswEKHzZEDkl21ekS3T6NefUrzVFsdyRS0A2qOHL1L4Nra5'}
> 
> 
> 
> 
> We have the same
> error on our testing LINUX system and our development environment on windows.
> We tried to call the REST function via local testing method, Android app and
> CURL – same behavior.
> 
> 
> The settings of UNICODE_JSON = True/False causes no difference.
> 
> 
> 
> 
> We tried it with a
> REST function without OAUTH Token creation (username and password 
> credentials) –
> same behavior.
> 
> 
> 
> 
> But – when we call
> the function with the arguments REST_CLIENT_ID and REST_CLIENT_SECRET
> the function is working fine: 
> 
> 
> curl -X POST -d
> "grant_type=password=emilia.muel...@email.com=qwertzui"
> -u"VAOpqwqOTl99jRVXY63Bv5uNXs2MpJWUlZSwSZBf:cgrDaIjPyAy45Z1yxarT0iP9UOjw7gvbpnMirgwz24A56EeJGONHYSsqs9eVPHAyLrsPZdwfdQxoGPnM4LFtihltxlrX24hCQIIE57JezwSHIJab9VjTwAjS9LxYFVJm"
> "127.0.0.1:8000/rest/oauth2/token/"
> 
> 
> response: {"access_token":
> "Fz7yTNSsdUxRaWuMj4Sf4OnPe0Ujf6", "expires_in": 3000,
> "token_type": "Bearer", "scope": "read
> write", "refresh_token": "r9H5E8MK5AAy57ZdiFUJaWaJT63kJL"}
> 
> 
> 
> But – when we tried to call the other functions with this token and are 
> getting the same encoding error (traceback below):  
> 
> 
> curl -X GET -H
> "Authorization: Bearer Fz7yTNSsdUxRaWuMj4Sf4OnPe0Ujf6"
> 127.0.0.1:8000/rest/patient/1
> 
> 
> Everything worked
> fine a few weeks ago, but after a database change the problem occurs. Setting
> the DB Model to the previous entries was not successful.
> 
> 
> 
> 
> It would be really
> great if some of you would have any idea what is working wrong here!
> Thanks in advance!
> 
> 
> Kerstin and Romy
> 
> 
> 
>  
> 
> 
> ---
> 
> Traceback
> 
>   
> Traceback (most recent call last):
>   File "C:\Python37\lib\site-packages\django\core\handlers\exception.py", 
> line 34, in inner
> response = get_response(request)
>   File "C:\Python37\lib\site-packages\django\core\handlers\base.py", line 
> 115, in _get_response
> response = self.process_exception_by_middleware(e, request)
>   File "C:\Python37\lib\site-packages\django\core\handlers\base.py", line 
> 113, in _get_response
> response = wrapped_callback(request, *callback_args, **callback_kwargs)
>   File "C:\Python37\lib\site-packages\django\views\decorators\csrf.py", line 
> 54, in wrapped_view
> return view_func(*args, **kwargs)
>   File "C:\Python37\lib\site-packages\django\views\generic\base.py", line 71, 
> in view
> return self.dispatch(request, *args, **kwargs)
>   File "C:\Python37\lib\site-packages\rest_framework\views.py", line 495, in 
> dispatch
> response = self.handle_exception(exc)
>   File "C:\Python37\lib\site-packages\rest_framework\views.py", line 455, in 
> handle_exception
> self.raise_uncaught_exception(exc)
>   File "C:\Python37\lib\site-packages\rest_framework\views.py", line 492, in 
> dispatch
> response = handler(request, *args, **kwargs)
>   File "C:\Users\andresr\InsisT\Server\insist_rest\views.py", line 93, in get
> return Response(self.serializer_class(patient[0]).data, 
> status=status.HTTP_200_OK)
>   File "C:\Python37\lib\site-packages\rest_framework\response.py", line 32, 
> in __init__
> super(Response, self).__init__(None, status=status)
>   File "C:\Python37\lib\site-packages\django\template\response.py", line 36, 
> in __init__
> 

DRF UnicodeDecodeError: 'utf-8' codec can't decode byte 0xf6

2019-10-21 Thread Kerstin Rohm
 

Dear Django Community,


we have a curious encoding error and we are running out of ideas to solve 
the problem.

We build a Django REST Service with the following packages: 

 

dj-database-url 0.5.0

Django 2.2.1

django-filter 2.1.0

django-oauth-toolkit 1.2.0

django-widget-tweaks 1.4.3

djangorestframework 3.9.3

python-decouple 3.1

argon2-cffi 19.1.0

plotly 4.1.1


When we call a specific REST function (e.g.

*@api_view*([*'POST'*])

*@permission_classes*([AllowAny])

def *token*(request):

r = requests.post(*'http://127.0.0.1:8000/rest/oauth2/token/'*,

  data={*'grant_type'* : *'password'*,

*'username'* : request.data[*'username'*],

*'password'* : request.data[*'password'*],

*'client_id'* : settings.REST_CLIENT_ID,

*'client_secret'* : 
settings.REST_CLIENT_SECRET,},)

return Response(r.json())

)


We are getting a UFT8 encoding error (Traceback see below). The content of 
“data” seems to be ok:


data= {'grant_type': 'password', 'username': 'x', 'password': 'x', 
'client_id': 'TQmAHzCM2r9nfkruVQw0eMQ0AziSvLAnf4ufvZ1o', 'client_secret': 
'GISUGXxa2e4JHejUCImMMUMJMtZ13byvc8fySUvX7shELNLPE5xZBA3p0cvbXvvrPIWgltSkTNZ9a7JHPQswEKHzZEDkl21ekS3T6NefUrzVFsdyRS0A2qOHL1L4Nra5'}


We have the same error on our testing LINUX system and our development 
environment on windows. We tried to call the REST function via local 
testing method, Android app and CURL – same behavior.

The settings of UNICODE_JSON = True/False causes no difference.


We tried it with a REST function without OAUTH Token creation (username and 
password credentials) – same behavior.


But – when we call the function with the arguments REST_CLIENT_ID and 
REST_CLIENT_SECRET the function is working fine: 

curl -X POST -d 
"grant_type=password=emilia.muel...@email.com=qwertzui" 
-u"VAOpqwqOTl99jRVXY63Bv5uNXs2MpJWUlZSwSZBf:cgrDaIjPyAy45Z1yxarT0iP9UOjw7gvbpnMirgwz24A56EeJGONHYSsqs9eVPHAyLrsPZdwfdQxoGPnM4LFtihltxlrX24hCQIIE57JezwSHIJab9VjTwAjS9LxYFVJm"
 
"127.0.0.1:8000/rest/oauth2/token/"

response: {"access_token": "Fz7yTNSsdUxRaWuMj4Sf4OnPe0Ujf6", "expires_in": 
3000, "token_type": "Bearer", "scope": "read write", "refresh_token": 
"r9H5E8MK5AAy57ZdiFUJaWaJT63kJL"} 


But – when we tried to call the other functions with this token and are getting 
the same encoding error (traceback below): 

 

curl -X GET -H "Authorization: Bearer Fz7yTNSsdUxRaWuMj4Sf4OnPe0Ujf6" 
127.0.0.1:8000/rest/patient/1

Everything worked fine a few weeks ago, but after a database change the 
problem occurs. Setting the DB Model to the previous entries was not 
successful.


It would be really great if some of you would have any idea what is working 
wrong here!

Thanks in advance!


Kerstin and Romy

 
---
Traceback
  

Traceback (most recent call last):
  File "C:\Python37\lib\site-packages\django\core\handlers\exception.py", line 
34, in inner
response = get_response(request)
  File "C:\Python37\lib\site-packages\django\core\handlers\base.py", line 115, 
in _get_response
response = self.process_exception_by_middleware(e, request)
  File "C:\Python37\lib\site-packages\django\core\handlers\base.py", line 113, 
in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "C:\Python37\lib\site-packages\django\views\decorators\csrf.py", line 
54, in wrapped_view
return view_func(*args, **kwargs)
  File "C:\Python37\lib\site-packages\django\views\generic\base.py", line 71, 
in view
return self.dispatch(request, *args, **kwargs)
  File "C:\Python37\lib\site-packages\rest_framework\views.py", line 495, in 
dispatch
response = self.handle_exception(exc)
  File "C:\Python37\lib\site-packages\rest_framework\views.py", line 455, in 
handle_exception
self.raise_uncaught_exception(exc)
  File "C:\Python37\lib\site-packages\rest_framework\views.py", line 492, in 
dispatch
response = handler(request, *args, **kwargs)
  File "C:\Users\andresr\InsisT\Server\insist_rest\views.py", line 93, in get
return Response(self.serializer_class(patient[0]).data, 
status=status.HTTP_200_OK)
  File "C:\Python37\lib\site-packages\rest_framework\response.py", line 32, in 
__init__
super(Response, self).__init__(None, status=status)
  File "C:\Python37\lib\site-packages\django\template\response.py", line 36, in 
__init__
super().__init__('', content_type, status, charset=charset)
  File "C:\Python37\lib\site-packages\django\http\response.py", line 289, in 
__init__
super().__init__(*args, **kwargs)
  File "C:\Python37\lib\site-packages\django\http\response.py", line 60, in 
__init__
content_type = '%s; charset=%s' % (settings.DEFAULT_CONTENT_TYPE,
  File "C:\Python37\lib\site-packages\django\conf\__init__.py", line 120, in 
DEFAULT_CONTENT_TYPE
stack = traceback.extract_stack()
  File "C:\Python37\lib\traceback.py", line 211, in extract_stack
stack =