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