无效的文件名或模式"wb" [英] Invalid filename or mode 'wb'

查看:125
本文介绍了无效的文件名或模式"wb"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用django.我试图使用Pythons图片库将用户上传的图标压缩为较小的尺寸.

I am using django. I was trying to compress an icon uploaded by a user to a smaller size using Pythons Image library.

以下是我的代码:

def resizeImage(icon,ext):
     path= os.path.join(settings.SITE_ROOT,'karnadash/static/tempfiles/temp'+ext)
     destination = open(path,'wb+')
     for chunk in icon.chunks():
         destination.write(chunk)
     destination.close()
     image = Image.open(path)
     image= image.resize((50, 50), Image.ANTIALIAS)
     image.save(path)
     return image

问题是我收到内部服务器错误.堆栈跟踪的最后一部分如下:

Problem is I am getting an internal server error. The last part of the stack trace is as follows:

 line 31, in resizeImage
     image.save(path)
 File "C:\Python27\lib\site-packages\PIL\Image.py", line 1446, in save
     fp = builtins.open(fp, "wb+")
IOError: [Errno 22] invalid mode ('wb') or filename: 'C:/Users/Silent/Documents/Python/karnadash/karnadash/static/tempfiles/temp.jpg'

有人可以解释为什么会这样吗?

Can anybody please explain why this is happening?

推荐答案

为我解决的问题是从反斜杠切换为正斜杠!谁会想到的?!

What solved it for me was switching from backslashes to forward slashes! Who would've thought?!

类似的帖子: ioerror无效模式w

这篇关于无效的文件名或模式"wb"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆