UnicodeDecodeError in socket.sendall with Django
NickName:Arun Kaushal Ask DateTime:2016-03-18T20:23:24

UnicodeDecodeError in socket.sendall with Django

I have following piece of code in client program which connects with server and sends a message to the server:

msg = struct.pack('!HH', 1, 152)

sock.sendall(msg + astr) # Here astr is an ascii string with length 148

When I run the client program from command line, it works fine. But when the program is invoked from Django, I get following error on the sock.sendall function line:

UnicodeDecodeError: 'ascii' codec can't decode byte 0x98 in position 3: ordinal not in range(128)

I searched for possible solutions for this and tried different solutions like setting LANG variable, using msg.encode('utf-8') but nothing worked.

Is it something to do with Django settings because it works fine when I invoke the program from shell.

Copyright Notice:Content Author:「Arun Kaushal」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/36084299/unicodedecodeerror-in-socket-sendall-with-django

More about “UnicodeDecodeError in socket.sendall with Django” related questions

UnicodeDecodeError in socket.sendall with Django

I have following piece of code in client program which connects with server and sends a message to the server: msg = struct.pack('!HH', 1, 152) sock.sendall(msg + astr) # Here astr is an ascii st...

Show Detail

UnicodeDecodeError django

I got this error when loaded localhost:8000 in django project, and it was the same case in every django project 'utf8' codec can't decode byte 0x81 in position 501470: invalid start byte Request M...

Show Detail

UnicodeDecodeError Django MakeMessages

I am getting a UnicodeDecodeError on the Django makemessages command Traceback (most recent call last): File "manage.py", line 10, in <module> execute_from_command_line(sys.argv) Fil...

Show Detail

How can I solve UnicodeDecodeError in Django?

I am getting this error in Django: UnicodeDecodeError at /category/list/ 'utf8' codec can't decode byte 0xf5 in position 7: invalid start byte Request Method: GET Request URL: ... Django

Show Detail

Django UnicodeDecodeError in model object

this is another UnicodeDecodeError I'm dealing with in django. I can't find the way to solve it. I'm trying to create an object: nivel_obj = Nivel.objects.filter(id=nivel_id) nueva_matricula =

Show Detail

Unicodedecodeerror with runserver and django

After setup all that django requires, and try python manage.py runserver command, I caught error. How to fix it? Or at least how take a look on what caused error? Windows 7 python manage.py runser...

Show Detail

UnicodeDecodeError while running Django dev server

UnicodeDecodeError Appears while trying to access any of the files from site media folder. Full traceback presented in debug mode: Environment: Request Method: GET Request URL: http://127.0.0.1...

Show Detail

UnicodeDecodeError Django Error Collectstatic

i have a problem. I use collectstatic for production. But i have this problem with a css file. UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe1 in position 240647: invalid continuation byte...

Show Detail

UnicodeDecodeError sending mail Django

I'm trying to send email (doesn't matter what includes) using send_mail function from django.core.mail and it shows me this error all the time: I'm using Python 3.6.4 and Django 2.0.7

Show Detail

UnicodeDecodeError with compilemessages django translator

I get this error UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 5: ordinal not in range(128) while I want to comiple .po file using python django.admin.py manage.py

Show Detail