django-uwsgi icon indicating copy to clipboard operation
django-uwsgi copied to clipboard

UnicodeDecodeError: 'utf-8' codec can't decode byte 0x80 in position 0: invalid start byte

Open fb-erik opened this issue 8 years ago • 6 comments

I am using the email backend on django 1.8.16 and have tried both python 3.4.2 and 3.5.2 but always get the following error in the spooler:

django_uwsgi/decorators.py", line 38, in _decode1
    return val.decode('utf-8')
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x80 in position 0: invalid start byte

so I thought maybe it is the decode call on line 38 in the decorators and tried adding "ignore", but then I get the following error:

django_uwsgi/task.py", line 15, in send_mail
    conn.send_messages([pickle.loads(arguments['body'])])
TypeError: a bytes-like object is required, not 'str'

which feels like maybe there is some python 3 incompatibility? I'm also using the email backend on a site that uses python 2.7 where everything works fine.

fb-erik avatar Nov 07 '16 11:11 fb-erik

Thanks for report. I'll look into it a bit later. Yeah, uwsgi spooler needs bytes, not strings if running on python3 Recently I wanted to ditch python2.7 support, from this package. I'll fix this after next release(which is coming soon). Btw, decorators.py taken from uwsgi repo https://github.com/unbit/uwsgi/blob/master/uwsgidecorators.py and mostly not touched, except some imports. I'm using this file "as is", and if this file should be modified, it should be done in uwsgi repo. I'll try to figure it out.

MechanisM avatar Nov 07 '16 21:11 MechanisM

Thanks @MechanisM I appreciate it.

fb-erik avatar Nov 08 '16 09:11 fb-erik

I am just installed django version 1.11.5 and python 3.6.2. Got the same error: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xf6 in position 3: invalid start byte. When I started django miniserver.

ypokkinen avatar Oct 02 '17 13:10 ypokkinen

same error as @ypokkinen Not sure why I type string in '.py', run cmd 'python3 xx.py runserver', choose the app site and get UnicodeError

tyrantqiao avatar Dec 09 '17 16:12 tyrantqiao

We are having the same issue with python3.4

toabi avatar Aug 21 '19 07:08 toabi

Ineed the issue is here: https://github.com/unbit/uwsgi/blob/2.0.18/uwsgidecorators.py#L29-L33 - it tries to decode the bytes although they were never unicode-encoded because pickle.dumps created the bytes.

A try … catch UnicodeDecodeError: return val in the decorators.py is a quickfix for that.

toabi avatar Aug 21 '19 08:08 toabi