Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

python3 CGI 输出中文不显示问题 #3

Open
leon0625 opened this issue Jan 13, 2018 · 0 comments
Open

python3 CGI 输出中文不显示问题 #3

leon0625 opened this issue Jan 13, 2018 · 0 comments
Labels

Comments

@leon0625
Copy link
Owner

leon0625 commented Jan 13, 2018

  问题是这样的,我用python3写后台CGI的时候,print了中文,但是页面显示不出来

后台代码这个样子:
image
前台代码这个样子:
image

调试的时候发现这中文其实已经传过来了
image
但显示不了,我以为是编码的问题,把以前对编码的总结又翻了一遍,还google了一下,发现网上的解决方法有两种

  1. python脚本开头加入如下语句(据说这是针对windows上python的操作)
import codecs, sys 
sys.stdout = codecs.getwriter('utf8')(sys.stdout.buffer)
  1. http头添加utf-8 charset
print("Content-type: application/json; charset="utf-8"\r\n\r\n")

第二条早上起来,就把这两种方法都试了下,发现都不行。。。

最后发现问题在哪儿呢?
变量名字写错了!前台读的location,我后台传的loction。我勒个去,就这bug,看了我好久没看出来。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant