一、场景

本人写了个前端,又写个django2.2后端,进行联调时出现此错误

UnicodeDecodeError: 'gbk' codec can't decode byte 0xa6 in position 9737: illegal multibyte sequence

二、解体思路

  • 我先用python request模块调用一下,发现是可以的
  • 然后用vue调用是不可以的,报上面的错误

有博文说更改django原码 ​​django\views\debug.py文件​

with Path(CURRENT_DIR, 'templates', 'technical_500.html').open() as fh
改成:
with Path(CURRENT_DIR, 'templates', 'technical_500.html').open(encoding="utf-8") as fh

不知什么原因不适合我的场景,因为我的
用python 的requests 模块是可以请求,vue 则不可以请求

ruquests.get(url='http://localhost:8080/api/v1/login')
ruquests.get(url='http://localhost:8080/api/v1/login/')

三、我的解决办法

  • 解法一 django 路由去掉最后一个 /
  • UnicodeDecodeError: ‘gbk‘ codec can‘t decode byte 0xa6 in position 9737: illegal multibyte sequence_django

  • 解法二 vue 路由添加一个 /
  • UnicodeDecodeError: ‘gbk‘ codec can‘t decode byte 0xa6 in position 9737: illegal multibyte sequence_python_02