2017-05-01 9 views
0

私は単純なWebサーバーを構築するためにpython tornadoを使用しています。
竜巻: 'utf-8'コーデックはバイトをデコードできません

import json 
import tornado.httpserver 
import tornado.ioloop 
import tornado.options 
import tornado.web 

from tornado.options import define, options 
define("port", default=80, help="run on the given port", type=int) 

class IndexHandler(tornado.web.RequestHandler): 
     def get(self, param): 
      print("\n\nthis is a get request from indexhandler:") 
      if param: 
       print("param is NOT null") 
       self.render(r"frontend/" + param) 
      else: 
       print("param is null") 
       self.render(r"frontend/index.html") 

if __name__ == "__main__": 
    tornado.options.parse_command_line() 
    app = tornado.web.Application(handlers=[(r"/(.*)", IndexHandler)]) 
    http_server = tornado.httpserver.HTTPServer(app) 
    http_server.listen(options.port) 
    tornado.ioloop.IOLoop.instance().start() 

すべてのフロントエンドコードのは、私は、このようなJSファイルやCSSファイルなど、/frontend中のすべてのリソースへのアクセスをユーザーに許可するために、単純な正規表現(.*)を使用/frontendのディレクトリにあります。ここでは竜巻のコードがあります。私は私のウェブサイトを訪問しようとすると、

しかし、私はすべてのリソースにアクセスすることはできません:サーバーの側で
enter image description here

を、私は以下のように多くのエラーを取得:

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

フロントエンドコードにいくつかの中国語があるからだと思います。

この問題を解決するにはどうすればよいですか?

Btw、私はリモートCentOSのコマンドラインで作業しているし、デスクトップがありません。

答えて

0

はあなたのスクリプトの先頭に

# -*- coding: UTF-8 -*- 

を追加しようとしたことがありますか? それを修正するかどうか分かりませんが、試行を傷つけることはありません

関連する問題