uliweb
uliweb copied to clipboard
_generate_etag will get exception with unicode filename which cannot encode by ascii
For example for the file path: u'/home/zhangclb/Dropbox/life/dudu/201804_\u7167\u7247/TIM\u56fe\u724720180428103333.jpg' will get this kind of exception:
u'/home/zhangclb/Dropbox/life/dudu/201804_\u7167\u7247/TIM\u56fe\u724720180428103333.jpg'
Traceback (most recent call last):
File "/home/zhangclb/oss/uliweb/uliweb/contrib/staticfiles/wsgi_staticfiles.py", line 91, in __call__
return self.app(environ, start_response)
File "/home/zhangclb/oss/uliweb/uliweb/core/SimpleFrame.py", line 1505, in __call__
response = self._open(environ)
File "/home/zhangclb/oss/uliweb/uliweb/core/SimpleFrame.py", line 1450, in _open
response = self.call_view(mod, handler_cls, handler, req, res, kwargs=values)
File "/home/zhangclb/oss/uliweb/uliweb/core/SimpleFrame.py", line 993, in call_view
result = self.call_handler(handler, request, response, env, wrap, args, kwargs)
File "/home/zhangclb/oss/uliweb/uliweb/core/SimpleFrame.py", line 1104, in call_handler
result = self._call_function(handler, request, response, env, args, kwargs)
File "/home/zhangclb/oss/uliweb/uliweb/core/SimpleFrame.py", line 1097, in _call_function
result = handler(*args, **kwargs)
File "/home/zhangclb/sandbox/mmscope/mmscope/apps/mmfile/views.py", line 77, in img_thumbnail
return filedown(request.environ,filename=filename,real_filename=real_filename)
File "/home/zhangclb/oss/uliweb/uliweb/utils/filedown.py", line 176, in filedown
etag = _generate_etag(mtime, file_size, real_filename)
File "/home/zhangclb/oss/uliweb/uliweb/utils/filedown.py", line 25, in _generate_etag
adler32(real_filename) & 0xffffffff
UnicodeEncodeError: 'ascii' codec can't encode characters in position 40-41: ordinal not in range(128)127.0.0.1 - - [2018-05-22 18:02:37] "GET /mmfile/img_thumbnail?id=2 HTTP/1.1" 500 95120 0.354206