开发者

'ascii' codec can't decode byte (problem when using django)

开发者 https://www.devze.com 2023-04-06 16:04 出处:网络
I wrote a simple html parsing class in python and it seems to work fine and then I try to use it with django and I get this error:

I wrote a simple html parsing class in python and it seems to work fine and then I try to use it with django and I get this error:

'ascii' codec can't decode byte 0xc2 in position 54465: ordinal not in range(128)

which is strange because I added this: # encoding: utf-8 to the top of my class. I d开发者_运维知识库on't really know much about encoding but can someone perhaps give me an idea of what's going here? Btw, I also insured that the source html was already in utf-8. Thanks!


Try putting that line at the top of your file. According to PEP 263, it has to be in the top two lines.


okay, I got it. All I needed to do was include # -*- coding: utf-8 -*- in the django view as well and that solved it!

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号