Forum Archive

Error when trying to get a photo attachment in a mail

cvp

I only try to get a photo attached in a mail and I get an error...
When I first save the image in the camera roll and I use the same script to get it, no error
Help needed
Thanks

# coding: utf-8
import appex
img = appex.get_image(image_type='pil')

UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 0: invalid start byte

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/private/var/mobile/Containers/Shared/AppGroup/BC53E549-355D-4E77-BC46-64C3D3E0BDAF/Pythonista3/Documents/x.py", line 3, in
img = appex.get_image(image_type='pil')
File "/var/containers/Bundle/Application/606A7B2D-313E-48DB-BEB5-79336C85A91D/Pythonista3.app/Frameworks/PythonistaKit3.framework/pylib/site-packages/appex.py", line 97, in get_image
image_attachments = get_attachments('public.image')
File "/var/containers/Bundle/Application/606A7B2D-313E-48DB-BEB5-79336C85A91D/Pythonista3.app/Frameworks/PythonistaKit3.framework/pylib/site-packages/appex.py", line 38, in get_attachments
input_items = get_input()
SystemError: returned a result with an error set

lukaskollmer

How do you open the Pythonista extension from Mail?

cvp

Long press on the photo, run Pythonista script

ccc

Try running apex_dump.py in place of your script to see exactly what mail is passing to you. Did you try with jpeg instead of PIL?

lukaskollmer

@ccc @cvp it doesn't work at all. appex.get_input crashes as well.

Getting the image is not impossible though, since workflow can do it. (Create a new workflow with a single Quick Look action that accepts everything to test)

cvp

@ccc
Same error

UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 0: invalid start byte

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/private/var/mobile/Containers/Shared/AppGroup/BC53E549-355D-4E77-BC46-64C3D3E0BDAF/Pythonista3/Documents/t2.py", line 15, in
main()
File "/private/var/mobile/Containers/Shared/AppGroup/BC53E549-355D-4E77-BC46-64C3D3E0BDAF/Pythonista3/Documents/t2.py", line 12, in main
print('{:<11} : {}'.format(name.partition('_')[2], func()))
File "/var/containers/Bundle/Application/606A7B2D-313E-48DB-BEB5-79336C85A91D/Pythonista3.app/Frameworks/PythonistaKit3.framework/pylib/site-packages/appex.py", line 38, in get_attachments
input_items = get_input()
SystemError: returned a result with an error set

cvp

@lukaskollmer

If I use ViewExif, it functions but Pythonista 3 crashes

cvp

Forcing Python 2 functions! bug of Python 3?

ccc

Workaround is to make sure that #! python2 is the first line of your script.

cvp

@ccc

That's what I did when I said it's ok in Python 2

cvp

As adviced by @ccc, this is ok even in Python 3

#img = appex.get_image()
f = appex.get_attachments()
img = Image.open(f[0])
omz

A SystemError exception is nearly always a bug on my part. I'll look into it.

cvp

Thanks
Not vital as workaround of @ccc solves it.