私は単純な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
のディレクトリにあります。ここでは竜巻のコードがあります。私は私のウェブサイトを訪問しようとすると、
しかし、私はすべてのリソースにアクセスすることはできません:サーバーの側で
を、私は以下のように多くのエラーを取得:
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xa8 in position 14: invalid start byte
フロントエンドコードにいくつかの中国語があるからだと思います。
この問題を解決するにはどうすればよいですか?
Btw、私はリモートCentOSのコマンドラインで作業しているし、デスクトップがありません。