Python——python3版本解决ImageFile._save报TypeError: string argument expected, got 'bytes'

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

前言:

     还是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/.virtualenv
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值