【问题标题】:JpegImageFile instance has no __call__ method with StringIOJpegImageFile 实例没有带有 StringIO 的 __call__ 方法
【发布时间】:2015-04-07 10:33:15
【问题描述】:

当我从服务器获取二进制文件时,我通过r.content 访问它。问题是我想将此二进制文件转换为图像,然后将其发送到浏览器,如下所示:

i = Image.open(StringIO(r.content))

但是调用它会返回以下错误:

AttributeError('JpegImageFile instance has no __call__ method',) 

或者例如:

AttributeError('PngImageFile instance has no __call__ method',)

此代码来自python documentation

【问题讨论】:

  • 你能展示你剩下的代码吗?你是如何阅读图像的?并存储它?听起来问题很可能是因为您的图像名称,也许它与您代码中的其他对象冲突!
  • 不确定您的具体问题,但您是否考虑过将图像下载到临时文件然后打开它?
  • 存储服务器在别处。我只是通过requests.postKasraAD、@SeanAzlin 上传到该存储服务器

标签: python binary python-requests stringio


【解决方案1】:

我在flask.helpers 中使用send_file 解决了它,如下所示:

my_file = StringIO(r.content)
send_file(my_file)

;-)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-07-22
    • 1970-01-01
    • 2023-04-03
    • 2012-07-04
    • 2018-02-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多