前言:
还是tornado迁移python3版本项目,图片验证码使用内存保存时候验证码出不来,报了TypeError: string argument expected, got 'bytes';
具体报错如下:
[E 191102 15:11:44 web:1788] Uncaught exception GET /api/piccode?pre=&cur=88508b02-5c21-4ff4-a7eb-dcf01ceb35bf (::1)
HTTPServerRequest(protocol='http', host='localhost:8090', method='GET', uri='/api/piccode?pre=&cur=88508b02-5c21-4ff4-a7eb-dcf01ceb35bf', version='HTTP/1.1', remote_ip='::1')
Traceback (most recent call last):
File "/Users/dongchao/.virtualenvs/py_django/lib/python3.7/site-packages/PIL/ImageFile.py", line 498, in _save
fh = fp.fileno()
io.UnsupportedOperation: fileno
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/dongchao/.virtualenvs/py_django/lib/python3.7/site-packages/tornado/web.py", line 1697, in _execute
result = method(*self.path_args, **self.path
Python3解决ImageFile._save报TypeError问题

在将Tornado项目从Python2迁移至Python3时,遇到ImageFile._save报错:TypeError: string argument expected, got 'bytes'。问题源于Python3中将StringIO替换为io.StringIO()。解决方法是参照简书CoderZb的文章,通过导入相关模块并更改保存方法来修复此问题。"
86612223,1334135,基于RBAC的开源框架flyray-targe:天盾,"['架构设计', 'Java开发', '数据库管理', '微服务', '前端开发']
最低0.47元/天 解锁文章
2241

被折叠的 条评论
为什么被折叠?



