Page 1 of 3

Once again down that hole

PostPosted: Sun Jun 10, 2018 2:19 pm
by Different Computers
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.

Re: Once again down that hole

PostPosted: Sun Jun 10, 2018 4:32 pm
by RogueProeliator
Did you try escaping the path's spaces in case it does not like those?

Adam

Re: Once again down that hole

PostPosted: Sun Jun 10, 2018 4:48 pm
by Different Computers
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.

Re: Once again down that hole

PostPosted: Sun Jun 10, 2018 5:03 pm
by agame
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 ....

Re: Once again down that hole

PostPosted: Sun Jun 10, 2018 5:23 pm
by jay (support)
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?

Re: Once again down that hole

PostPosted: Sun Jun 10, 2018 6:30 pm
by Different Computers
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.

Re: Once again down that hole

PostPosted: Mon Jun 11, 2018 4:38 pm
by Different Computers
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?

Re: Once again down that hole

PostPosted: Mon Jun 11, 2018 5:54 pm
by jay (support)
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.

Re: Once again down that hole

PostPosted: Mon Jun 11, 2018 9:04 pm
by Different Computers
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.

Re: Once again down that hole

PostPosted: Mon Jun 11, 2018 9:22 pm
by Different Computers
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.

Re: Once again down that hole

PostPosted: Tue Jun 12, 2018 3:53 am
by DaveL17
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).

Re: Once again down that hole

PostPosted: Tue Jun 12, 2018 6:52 am
by berkinet
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.

Re: Once again down that hole

PostPosted: Tue Jun 12, 2018 8:19 am
by Different Computers
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.

Re: Once again down that hole

PostPosted: Tue Jun 12, 2018 9:06 am
by berkinet
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)

Re: Once again down that hole

PostPosted: Tue Jun 12, 2018 9:15 am
by Different Computers
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.