hoping someone might be able to help a complete newbie here. I am connected to a terminal session in my pi zero via putty and Xming Server and have installed feh to inspect image files. so if I enter

sudo feh myimage.jpg

it launches a new x- window and shows the image perfectly over the remote connection on my laptop. So what I would like to do is have this run via a python script.

def displaylastimage():

    if not os.path.exists(cameraproperties.lastimage):
        print("file not found")
        lastimagefilecmd = str("feh "+ cameraproperties.lastimage)
            os.system(lastimagefilecmd)  #Try no1       
            os.system("DISPLAY=:0.0 XAUTHORITY=/home/pi/.Xauthority"+lastimagefilecmd)   #Try no2
            image = subprocess.Popen(["feh", cameraproperties.lastimage])   # try no3
            subprocess.Popen(lastimagefilecmd, shell=True)     #try no 4 
        except Exception as Er:
            print("something went wrong")

Every time I get the same error:

PuTTY X11 proxy: Unsupported authorisation protocol
Feh ERROR: Can't open X display. It *is* running, yeah?

I guessing that Feh is being called but the output is taking a different route when called from python? Any suggestions about how one might go about fixing this? Thanks.


Typical, just when you ask a question, you get it to work. Following suggestions from https://www.raspberrypi.org/forums/viewtopic.php?t=60088

The problem appears to be that you are trying to connect an X client to the X display of a different user, and it does not have the correct authentication cookie.

I tried running the script without root privileges (no sudo) and it works fine. Still no idea why but I guess as was suggested in the other form, something to do with x client - x display and python! If anyone wants to explain this to me I would be delighted to learn.

  • Please mark the answer as the accepted one with a click on the tick on its left side. That prevents your Question from being shown as an unsolved Post to the community and saves them/us a lot of work. – Ingo Nov 30 '20 at 20:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.