Django解决UnicodeEncodeError: latin-1’ codec can’t encode characters in position 143-144: ordinal not in range(256)
起因
今天在用中文名字登陆Django写的网页时,发现无法用中文名字登陆,然后查看报错原因是
File "/xxxs/xxx/opt/anaconda3/envs/pytorch1/lib/python3.8/wsgiref/headers.py", line 142, in __bytes__
return str(self).encode('iso-8859-1')
UnicodeEncodeError: latin-1' codec can't encode characters in position 143-144: ordinal not in range(256)
解决方案
意思就是
…/pytorch1/lib/python3.8/wsgiref/headers.py 这个文件里的第142行
return str(self).encode('iso-8859-1')
无法识别中文,那么我们就可以点击这个文件,将其修改return str(self).encode('utf-8')
便可以直接登陆了