I am trying to run a wxpython script via VNC. When i try to open it i get the error:
X11 connection rejected because of wrong authentication.
Unable to access the X Display, is $DISPLAY set properly?
I solve it via:
xauth list
sudo xauth add raspberrypi/unix:10 MIT-MAGIC-COOKIE-1
and then the corresponding cookie. Thing is i wanted to automate this in the init of the script, so that the user would not need to do it every time. i have written the following script:
import subprocess
import string
p=subprocess.Popen(['xauth','list'],stdout=subprocess.PIPE)
(out,err)=p.communicate()
out1=out.split('\n')
for line in out1:
t=line.split()
y=subprocess.Popen(['sudo','xauth','add',t[0],t[1],t[2]],stdout=subprocess.PIPE)
which works fine but i am still not able to get the program to run. Checking the output i realize that i am not getting the same output if i run xauth list from shell and if i run it with Popen.
Any help would be much appreciated!
Related
I have an EMR cluster 5.28.1 running in AWS but I forgot to install from python libraries as part of the bootstrap action. Now that the cluster is running, I was simply attempting to add a step via the EMR console. Here are my settings
JAR: s3://us-east-1.elasticmapreduce/libs/script-runner/script-runner.jar
Main class: None
Arguments: s3://xxxx/install_python_libraries.sh
Unfortunately, I get the following error.
Cannot run program "s3://xxxxx/install_python_libraries.sh" (in directory "."): error=2, No such file or directory
I am not sure what I am doing wrong. The shell script looks like this.
#!/bin/bash -xe
# Non-standard and non-Amazon Machine Image Python modules:
sudo pip-3.6 install boto3
sudo pip-3.6 install xmltodict
I also tried this by simply using 'command-runner.jar' but I get the same error. Can you please help me figure out the problem so I do this via the console? I would like to install the libraries on all nodes - master and core.
Thanks
The issue is the xxx.sh files EOL/carriage return type.
In other words, if it is Windows ("\r\n") then it will not work and return the ./ file not found error.
Convert it to unix type ("\n") using something like notepad++ and it will run fine.
(In notepad++ edit>EOL Conversion>Unix(LF) hit save and try again)
When I run this command:
FLASK_APP=web.py flask run
I get this error:
File "<ipython-input-2-26c34e6a35fe>", line 1
FLASK_APP=web.py flask run
^
SyntaxError: invalid syntax
What am I missing?
You seem to be running a terminal command inside ipython based on the error message.
The problem with this is that you haven't told ipython that you're trying to run a terminal command.
In Jupyter Notebook you can execute Terminal commands in the notebook cells by prepending an exclamation point/bang(!) to the beginning of the command.
source
So do this instead:
!FLASK_APP=web.py flask run
I am new to Jenkins, specially with using python script in Jenkins. The problem I am facing is as follow:
I am trying to run a python script from a python file in the post-build step of the Jenkins. I have added all the plugins required for that purpose to my understanding. i.e I have included Post-BuildScript plugin, python jenkins plugin etc.
Now when I build console output shows invalid script command caused the failure. I have attached the results below. can anybody help me with that please?
In post build step I am providing the full or absolute path to the python script file i.e
ExecutepythonScriptpath
Results
It may be useful to mention here I have also tried using just the path without writing python preceding the path, also tried with forward as well as backward slash in the path. without any success.
I have managed to resolve that issue. There are two parts of solution:
First one is if you want to run simple python script in post-build -->Add a post build step for Execute python Script (That will require you install plugin for post build ) . In that window created after adding post build step you can simply put any python command to run.
Second part of the solution is for, when user would like to run a list of commands from a python script file from the same post build step window in that case user has to make sure to put all the required python files which you want to execute into the Jenkins workspace->project directory(project for which we are running the Jenkins ) .
Moreover, for Python2.7 in order to execute that python script file user simply need to write script as
execfile(file.py)
One more thing to remember is insert python.exe path in the environment variables.
I am trying to launch a Qt message box every minute. I added a line in crontab to run the Qt program's executable and redirected the error output to a file in my home directory.
There is no problem with the Qt program that launches the message box because I tested it, but when I try to launch it with crontab the following error arises:
QXcbConnection: Could not connect to display
Aborted (core dumped)
I checked that over the internet and found a thread that might be helpful: https://unix.stackexchange.com/questions/148945/could-not-connect-to-display-in-one-user-account/149026#149026
I believe the first response gives the solution but it's not clear.
It suggests to use x11 to share the desktop and xauth to add security measures but doesn't specify how to configure them. I have xauth already installed but the error persists.
Any ideas about how to solve this problem?
I think the DISPLAY environment is missing. I suggest you wrap your application in a wrapper script (let's call it horloge.sh):
#!/bin/sh
DISPLAY=:0
export DISPLAY
/home/salwa/computing/cpp/horloge
Then put the horloge.sh in your crontab. Don't forget to do a chmod u+x horloge.sh so that the script is executable.
Make sure that the user that launches your app in the crontab line is you. Otherwise, it may not have permissions to use the X server.
I have a html file with one button. When the button is clicked, a javascript function "run" is called:
function run() {
window.open("http://localhost/cgi-bin/run.py", "_self");
}
run.py is simply trying to run a helloworld.exe program, that outputs in a terminal the string "helloworld", but nothing happens, and browser keeps "waiting for localhost" indefinitely.
#!python
import sys, string, os, cgitb
cgitb.enable()
os.system("helloworld.exe")
I have tried helloworld.exe alone and it works, I have run run.py on the terminal, and it worked, and also I have tested on the browser the test site http://localhost/cgi-bin/helloworld.py, and it worked fine (helloworld.py is another script just to see if my apache is configured OK).
I am using wamp.
What I am trying to do is a bigger program that allows a client connect to a server, and "interact" with a program on the server side. The program is already done in c++, and won't be translated into php or javascript.
EDIT: I have been trying with the functions: subprocess.Popen, subprocess.call and os.system. I have also tested the code to run .exe files created by me living at apache/cgi-bin folder or executables like wordpad, living at c:\windows. And it always succeeds when the python script runs from the terminal, and it never works when trying from the browser. Is it possible that it is because of the server I am using? I use the apache from wamp, and have added the sentence "AddHandler cgi-script .exe" to the httpd.conf file.
I am sure it doesn't work locally. os.system returns you the exit code of the command, not its output.
You will need to use subprocess.Popen and pipeline the output to read the output.
import subprocess
p = subprocess.Popen("whatever.exe",stdout=subprocess.PIPE)
print p.stdout.read()
p.wait()
Also, the output of your CGI script is not valid HTTP protocol, and depending on your server that could be causing problems (some servers sanitize the output of the scripts, some others expect them to be written properly).
To me this code example works (on GNU/Linux using weborf as server, but it should be the same). You can try setting the content type and sending the \r\n\r\n final sequence. Servers are not expected to send that because the CGI script might want to add some more HTTP headers.
#!/usr/bin/env python
import cgitb
import subprocess
import sys
cgitb.enable()
sys.stdout.write("Content-type: text/plain\r\n\r\n")
p = subprocess.Popen("/usr/games/fortune",stdout=subprocess.PIPE)
data = p.stdout.read()
p.wait()
print data
In general my experience has been that if something works locally and doesn't work when you install all the same code on a different server, you are looking at a permissions problem. Check the permissions that visitors on your site have and make sure that the user coming through your web server has the right permissions to run helloworld.exe and run.py.