使用Flask发送静态文件会引发UnicodeDecodeError

时间:2016-04-12 17:58:44

标签: python flask

我试图链接到Flask中的静态css文件。但是,静态路由在尝试发送文件时会引发UnicodeDecodeError: 'ascii' codec can't decode byte 0xe5 in position 8: ordinal not in range(128)。为什么我会收到此错误以及如何解决?

<link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='content/alpin.css') }}"/>
Traceback (most recent call last):
  File "C:\Python27\lib\site-packages\flask-0.10.1-py2.7.egg\flask\app.py", line 1836, in __call__
    return self.wsgi_app(environ, start_response)
  File "C:\Python27\lib\site-packages\flask-0.10.1-py2.7.egg\flask\app.py", line 1820, in wsgi_app
    response = self.make_response(self.handle_exception(e))
  File "C:\Python27\lib\site-packages\flask-0.10.1-py2.7.egg\flask\app.py", line 1403, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "C:\Python27\lib\site-packages\flask-0.10.1-py2.7.egg\flask\app.py", line 1817, in wsgi_app
    response = self.full_dispatch_request()
  File "C:\Python27\lib\site-packages\flask-0.10.1-py2.7.egg\flask\app.py", line 1477, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "C:\Python27\lib\site-packages\flask-0.10.1-py2.7.egg\flask\app.py", line 1381, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "C:\Python27\lib\site-packages\flask-0.10.1-py2.7.egg\flask\app.py", line 1475, in full_dispatch_request
    rv = self.dispatch_request()
  File "C:\Python27\lib\site-packages\flask-0.10.1-py2.7.egg\flask\app.py", line 1461, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "C:\Python27\lib\site-packages\flask-0.10.1-py2.7.egg\flask\helpers.py", line 822, in send_static_file
    cache_timeout=cache_timeout)
  File "C:\Python27\lib\site-packages\flask-0.10.1-py2.7.egg\flask\helpers.py", line 612, in send_from_directory
    filename = safe_join(directory, filename)
  File "C:\Python27\lib\site-packages\flask-0.10.1-py2.7.egg\flask\helpers.py", line 582, in safe_join
    return os.path.join(directory, filename)
  File "C:\Python27\lib\ntpath.py", line 85, in join
    result_path = result_path + p_path
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe5 in position 8: ordinal not in range(128)

0 个答案:

没有答案