Forum Archive

Gives an error at the line that I marked.

happy_variable
# coding: utf-8
import ui
import appex
import Image


v = ui.load_view()
img = appex.get_image()
if img:
    v["image"].image = ui.Image(str(img)) #Error occurs here, it says IOError couldn't display image or something like that
v.present('sheet')
if not img:
    v.close()

How do I correct it? Please help!

uj_jonas

@happy_variable
I don't know why you get that error, but try appex.get_attachments()[0] instead of appex.get_image()
That did it for me :/

Oh, and remove the str() around img on the line you get the error

ccc

appex.get_image() had issues that are now fixed in the current beta... See https://forum.omz-software.com/topic/3498/error-when-trying-to-get-a-photo-attachment-in-a-mail and https://github.com/omz/Pythonista-Issues/issues/169

omz

I think the main problem here is that appex.get_image() returns a PIL.Image, but the ui.Image constructor expects an image name or file path...

Something like this should work (it's possible that workarounds are needed for the App Store version of Pythonista 3 because of the aforementioned bug in appex):

img_data = appex.get_image_data()
if img_data:
    v['image'].image = ui.Image.from_data(img_data)
# ...
happy_variable

Thanks a lot! THAT WORKS!!! Without you I could have wasted time on trying to correct this error!