2015-02-07 75 views
0

當我從服務器獲取二進制文件時,我通過r.content訪問它。問題是,我想這個二進制轉向圖像,然後將其發送給瀏覽器,如下:JpegImageFile實例沒有StringIO的__call__方法

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

但調用將返回以下錯誤:

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

,或者例如:

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

此代碼是從python documentation

+0

你能告訴你的代碼的其餘部分?你如何閱讀圖像?並存儲?很可能聽起來問題是因爲你的圖像名稱,或許它與你的代碼中的其他對象發生衝突! – Kasramvd 2015-02-07 08:58:22

+0

不確定您的具體問題,但您是否考慮過將圖像下載到臨時文件然後打開它? – 2015-02-07 08:59:55

+0

存儲服務器在別的地方。我只需通過'requests.post' @KasraAD,@SeanAzlin上傳到那個存儲服務器 – ALH 2015-02-07 09:30:31

回答

0

我解決它如下0 flask.helpers

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

;-)

相關問題