2020
10-24
10-24
解决Python 写文件报错TypeError的问题
处理上传的文件:f1=request.FILES['pic']fname='%s/%s'%(settings.MEDIA_ROOT,f1.name)withopen(fname,'w')aspic:forcinf1.chunks():pic.write(c)测试报错:TypeErrorat/upload/write()argumentmustbestr,notbytes把之前的打开语句修改为用二进制方式打开:f1=request.FILES['pic']fname='%s/%s'%(settings.MEDIA_ROOT,f1.name)withopen(fname,'wb+')aspic:forcinf1.chunks():...
继续阅读 >