Once again down that hole

Posted on
Sun Jun 10, 2018 2:19 pm
Different Computers offline
User avatar
Posts: 2533
Joined: Jan 02, 2016
Location: East Coast

Once again down that hole

I'm trying to work around that SSL issue I'm stuck with by using command line wget to put the image in
Code: Select all
/Library/Application Support/Perceptive Automation/Indigo 7/IndigoWebServer/public/


I've got that working in a test environment (meaning I run it manually at the command line). But then I have the hurdle I had before--the image straight copied over from the camera is too big for IWS/the reflector to serve.

So I'm trying to repurposethe old script that is here to compress the image. And that's the first hole I fall down. (the second is getting python to call wget using subprocess, but I can live with that not working for now.)
Code: Select all
from PIL import Image
import math, StringIO
BigImage = Image.open("/Library/Application Support/Perceptive Automation/Indigo 7/IndigoWebServer/public/" + "whatever.jpg")
im = Image.open(StringIO.StringIO(BigImage))

results in "IOError: cannot identify image file '/Library/Application Support/Perceptive Automation/Indigo 7/IndigoWebServer/public/whatever.jpg'"


I've researched the hell out of this and almost every answer I find talks about way over my head stuff about PIL not being right and issues with the library, but I bet my problem is much much more basic than that.

Anyone have insights? There definitely is a whatever.jpg in that location.

SmartThings refugee, so happy to be on Indigo. Monterey on a base M1 Mini w/Harmony Hub, Hue, DomoPad, Dynamic URL, Device Extensions, HomeKitLink, Grafana, Plex, uniFAP, Fantastic Weather, Nanoleaf, LED Simple Effects, Bond Home, Camect.

Posted on
Sun Jun 10, 2018 4:32 pm
RogueProeliator offline
User avatar
Posts: 2501
Joined: Nov 13, 2012
Location: Baton Rouge, LA

Re: Once again down that hole

Did you try escaping the path's spaces in case it does not like those?

Adam

Posted on
Sun Jun 10, 2018 4:48 pm
Different Computers offline
User avatar
Posts: 2533
Joined: Jan 02, 2016
Location: East Coast

Re: Once again down that hole

I'm pretty sure that's not it. The error returned:
Code: Select all
IOError: cannot identify image file '/Library/Application Support/Perceptive Automation/Indigo 7/IndigoWebServer/public/whatever.jpg'
shows the proper path. It's finding the file, but it can't identify it as an image file. I think.

I also tried escaping it (with \ in front of each space) and it screwed up the path.

Also tried it with r as an option:
Code: Select all
BigImage = Image.open(r"/Library/Application Support/Perceptive Automation/Indigo 7/IndigoWebServer/public/whatever.jpg")
Same error.

SmartThings refugee, so happy to be on Indigo. Monterey on a base M1 Mini w/Harmony Hub, Hue, DomoPad, Dynamic URL, Device Extensions, HomeKitLink, Grafana, Plex, uniFAP, Fantastic Weather, Nanoleaf, LED Simple Effects, Bond Home, Camect.

Posted on
Sun Jun 10, 2018 5:03 pm
agame offline
Posts: 514
Joined: Jul 13, 2017
Location: Melbourne, Australia

Re: Once again down that hole

presumably too simple...but I encountered a similar problem with image files not being recognised using the Image Downloader and Security Spy Helper plugin until I changed the file extension from .jpg to .jpeg ....

Posted on
Sun Jun 10, 2018 5:23 pm
jay (support) offline
Site Admin
User avatar
Posts: 18200
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Once again down that hole

But you can open the image in a image editor app and it opens correctly? Seems like the PIL library isn't liking the downloaded image. Perhaps use curl instead of wget?

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Sun Jun 10, 2018 6:30 pm
Different Computers offline
User avatar
Posts: 2533
Joined: Jan 02, 2016
Location: East Coast

Re: Once again down that hole

Thanks guys,

It does look like wget isn't getting the image properly. Which is odd, because for a while, it was. That's why I hadn't double checked to make sure the file was good.

SmartThings refugee, so happy to be on Indigo. Monterey on a base M1 Mini w/Harmony Hub, Hue, DomoPad, Dynamic URL, Device Extensions, HomeKitLink, Grafana, Plex, uniFAP, Fantastic Weather, Nanoleaf, LED Simple Effects, Bond Home, Camect.

Posted on
Mon Jun 11, 2018 4:38 pm
Different Computers offline
User avatar
Posts: 2533
Joined: Jan 02, 2016
Location: East Coast

Re: Once again down that hole

More poking.

Even when I run the wget manually, and get a valid image that opens fine in Preview, I still get "Cannot identify image file <StringIO.StringIO instance at 0x10fe1de18>. when I try to run this script:

Code: Select all
im = Image.open(StringIO.StringIO("/Library/Application Support/Perceptive Automation/Indigo 7/IndigoWebServer/public/whatever.jpg"))
And here, when I search for an answer to this issue, is where I get all the "your library is out of date" and "add the library to your egg.python" and similar things I know nothing about.

And it gets stranger! I added
Code: Select all
BigImage = Image.open('/Library/Application Support/Perceptive Automation/Indigo 7/IndigoWebServer/whatever.jpg')
BigImage.show()
im = Image.open(StringIO.StringIO(BigImage))

and BigImage.show works! Pops right open. So .show is working, meaning PIL is working, right? But stringIO is not?

SmartThings refugee, so happy to be on Indigo. Monterey on a base M1 Mini w/Harmony Hub, Hue, DomoPad, Dynamic URL, Device Extensions, HomeKitLink, Grafana, Plex, uniFAP, Fantastic Weather, Nanoleaf, LED Simple Effects, Bond Home, Camect.

Posted on
Mon Jun 11, 2018 5:54 pm
jay (support) offline
Site Admin
User avatar
Posts: 18200
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Once again down that hole

Wait - I think you've been chasing your tail. The original script was creating an image from a bit stream (which was an HTTP download), which is why it's using StringIO. But you're reading it from the disk directly using the Image.open() method. What you're getting back (you call it BigImage) is just, in fact, an Image object, which you can just call the methods on to adjust the size. Passing that image to StringIO won't work because it's not a bit string, it's a Python Image object.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Mon Jun 11, 2018 9:04 pm
Different Computers offline
User avatar
Posts: 2533
Joined: Jan 02, 2016
Location: East Coast

Re: Once again down that hole

Thanks Jay. That was the hint I needed. Part of the problem of using tools before you know what they really do!

I got it working just right, but then of course I managed to delete the whole script 5 minutes later, while thinking I had saved it under another name. Redoing almost from scratch now.

SmartThings refugee, so happy to be on Indigo. Monterey on a base M1 Mini w/Harmony Hub, Hue, DomoPad, Dynamic URL, Device Extensions, HomeKitLink, Grafana, Plex, uniFAP, Fantastic Weather, Nanoleaf, LED Simple Effects, Bond Home, Camect.

Posted on
Mon Jun 11, 2018 9:22 pm
Different Computers offline
User avatar
Posts: 2533
Joined: Jan 02, 2016
Location: East Coast

Re: Once again down that hole

OK, I'm SO close.

I even had it before I fumble fingered it. But apparently there's something I don't know about escaping characters in Python (and maybe not even Python, but subprocess.Popen) that is mystifying me.

At the bash command line this works
Code: Select all
wget --user name --password value --no-check-certificate 192.168.999.999/cgi-bin/currentpic.cgi -O /Library/Application\ Support/Perceptive\ Automation/Indigo\ 7/IndigoWebServer/public/whatever.jpg


But when I try
Code: Select all
subprocess.Popen("wget --user name --password value --no-check-certificate 192.168.999.999/cgi-bin/currentpic.cgi -O /Library/Application\ Support/Perceptive\ Automation/Indigo\ 7/IndigoWebServer/public/whatever.jpg")
it fails with "No such file or directory." I've tried it with and without escapes for the spaces in the path.

I've tried invoking Python at the command line, and dragging the target file into that command line, to see how it encodes.

I've tried subprocess.Popen(r with no change.

SmartThings refugee, so happy to be on Indigo. Monterey on a base M1 Mini w/Harmony Hub, Hue, DomoPad, Dynamic URL, Device Extensions, HomeKitLink, Grafana, Plex, uniFAP, Fantastic Weather, Nanoleaf, LED Simple Effects, Bond Home, Camect.

Posted on
Tue Jun 12, 2018 3:53 am
DaveL17 offline
User avatar
Posts: 6744
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: Once again down that hole

Try this construction:
Code: Select all
subprocess.Popen(["wget", "--user name", "--password value", "--no-check-certificate", "192.168.999.999/cgi-bin/currentpic.cgi", "-O", "/Library/Application\ Support/Perceptive\ Automation/Indigo\ 7/IndigoWebServer/public/whatever.jpg"])

I believe that subprocess requires the arguments to be in a list (that's from memory and untested).

I came here to drink milk and kick ass....and I've just finished my milk.

[My Plugins] - [My Forums]

Posted on
Tue Jun 12, 2018 6:52 am
berkinet offline
User avatar
Posts: 3290
Joined: Nov 18, 2008
Location: Berkeley, CA, USA & Mougins, France

Re: Once again down that hole

Different Computers wrote:
... this works
Code: Select all
wget --user name --password value --no-check-certificate 192.168.999.999/cgi-bin/currentpic.cgi -O /Library/Application\ Support/Perceptive\ Automation/Indigo\ 7/IndigoWebServer/public/whatever.jpg
But when I try
Code: Select all
subprocess.Popen("wget --user name --password value --no-check-certificate 192.168.999.999/cgi-bin/currentpic.cgi -O /Library/Application\ Support/Perceptive\ Automation/Indigo\ 7/IndigoWebServer/public/whatever.jpg")
it fails....

I suspect the problem has to do with long arg names (aka GNU style or double hyphen). When I tried to call curl using subprocess.Popen I ran into the same problem and had to resort to using a single argument, as you have tried. I think the problem may be in the way you are escaping the Indigo path. Two suggestions:
  1. Try this
    Code: Select all
    subprocess.Popen('wget --user name --password value --no-check-certificate 192.168.999.999/cgi-bin/currentpic.cgi -O "/Library/Application Support/Perceptive Automation/Indigo 7/IndigoWebServer/public/whatever.jpg"')
  2. Or try creating a symlink to the image, like
    Code: Select all
    ln -s  /Library/Application\ Support/Perceptive\ Automation/Indigo\ 7/IndigoWebServer/public/whatever.jpg  $HOME/whatever.jpg
    and then you avoid the problem.

Posted on
Tue Jun 12, 2018 8:19 am
Different Computers offline
User avatar
Posts: 2533
Joined: Jan 02, 2016
Location: East Coast

Re: Once again down that hole

Thanks guys. I'll keep plugging at this. I feel doubly stupid because I had it working and fumbled management of the Action Group that had the script in it.

subprocess.Popen is maddening because I read that stuff about the list, and tried it and it didn't work, even when I pulled apart a working wget statement and list-ified it. I also don't understand why the wget works perfectly at the bash command line, but doesn't work in Python, either with or without the escaped spaces.

I can try the symlink thing.

SmartThings refugee, so happy to be on Indigo. Monterey on a base M1 Mini w/Harmony Hub, Hue, DomoPad, Dynamic URL, Device Extensions, HomeKitLink, Grafana, Plex, uniFAP, Fantastic Weather, Nanoleaf, LED Simple Effects, Bond Home, Camect.

Posted on
Tue Jun 12, 2018 9:06 am
berkinet offline
User avatar
Posts: 3290
Joined: Nov 18, 2008
Location: Berkeley, CA, USA & Mougins, France

Re: Once again down that hole

Different Computers wrote:
Thanks guys. I'll keep plugging at this..

When passing a single command to subprocess.Popen you need to set shell=True...
    If passing a single string, either shell must be True
    or else the string must simply name the program to
    be executed without specifying any arguments.
Soooo
Code: Select all
subprocess.Popen('wget --user name --password value --no-check-certificate 192.168.999.999/cgi-bin/currentpic.cgi -O "/Library/Application Support/Perceptive Automation/Indigo 7/IndigoWebServer/public/whatever.jpg"', stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
To make it a little easier to manage, you might want to set the command arg forsubprocess.Popen as a variable. Like
Code: Select all
popenArgs = 'wget --user name --password value --no-check-certificate 192.168.999.999/cgi-bin/currentpic.cgi -O "/Library/Application Support/Perceptive Automation/Indigo 7/IndigoWebServer/public/whatever.jpg"'
subprocess.Popen(popenArgs,  stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)

Posted on
Tue Jun 12, 2018 9:15 am
Different Computers offline
User avatar
Posts: 2533
Joined: Jan 02, 2016
Location: East Coast

Re: Once again down that hole

So close now!

The subprocess works with shell=True.

Now I'm just stuck on little end result bits that require me to be at the computer to fix them. I'm optimistic!

I also really appreciate all your assistance and patience. I am fully aware that I'm like a kid reaching into the drawer full of kitchen knives here, grabbing tools I don't really know how to use yet.

SmartThings refugee, so happy to be on Indigo. Monterey on a base M1 Mini w/Harmony Hub, Hue, DomoPad, Dynamic URL, Device Extensions, HomeKitLink, Grafana, Plex, uniFAP, Fantastic Weather, Nanoleaf, LED Simple Effects, Bond Home, Camect.

Who is online

Users browsing this forum: No registered users and 1 guest