I have an app on my website, and I run it with Python from the Windows Command Prompt.
When I try opening it like this,
python http://www.erickwilts.nl/apps/app.py
it says:
python: can't open file 'http://www.erickwilts.nl/apps/app.py': [Errno 22] Invalid argument
Is there a way I can do this?
Since the resource is located on webserver, you must download it first.
You can do it with urllib2
import urllib2
exec(urllib2.urlopen("http://www.erickwilts.nl/apps/app.py").read())
executing scripts like this is really dangerous though.
What I really wanted is to execute the file on the webserver itself. Luckily, I had help from some more experienced guys, who helped me on installing python on the webserver en executing my script from my own computer using ssh.
Related
I have developed a Python web server using Flask, and some of the endpoints make use of the subprocess module to call different executables. On development, using the Flask debug server, everything works fine. However, when running the server along with nginx+WSGI (on the exact same machine), some subprocess calls fail.
For example, one of the tools I'm using is Microsoft's dotnet, which I installed from my user as sudo apt-get install -y aspnetcore-runtime-5.0 and is then called from Python with the subprocess module. When I run the server with python3 server.py, it works like a charm. However, when using nginx and WSGI, the subprocess call fails with an exception that says: /bin/sh: 1: dotnet: not found.
I suspect this is due to the command not being accessible to the user and group running the server. I have used this guide as a reference to deploy the app, and on the wsgi .ini file, I have set uid = javierd and gid = www-data, while on the systemd .service file I have User=javierd, Group=www-data.
I have tried to add the executables' paths to /etc/profile, but it didn't work, and I don't know any other way to fix it. I find also very surprising that this happens to some executables, but not to all, and that it happes to dotnet, for example, which is located at /usr/bin/dotnet and therefore should be accessible to every user. Any idea on how to solve this problem? Furthermore, if somebody could explain me why this is happening, I would really appreciate the effort.
Thanks a lot!
Ok, finally after having a big headache, I noticed the error, and it was really simple.
On the tutorial I linked, when creating the system service file, the following line was included: Environment="PATH=/home/myuser/myfolder/enviroment/bin".
Of course, as this was overriding the path, there was no way of executing the commands. Once I notices it I just removed that line, restarted the service, and it was fixed.
I have a Djnago web application on IIS 6 on one server. Is there a way that from this website I call another python script that is on another server in such a way that that script just run itself there?
Calling or Runnig that script in the usual way as internet says, is not working.
I always get the error of os.getcwd() and it also doesn't allow to change that directory.
I just want to run that python script there on that server from this server.
Can anyone help?
Normally, I would recommend using a framework like fabric or winrm if you want to run a python script on another server. Those frameworks use ssh or windows remoting functionality, respectively, to allow a python program to execute other commands (including python scripts) on other systems. If the target machine is a windows machine, be forewarned that you can run into all sorts of UAC issues doing normal operations.
My Python program uses the terminal(system) command to perform the task on the file and script. I am going to convert this Python program into Mac OS application and Linux application using pyinstaller. I am going to pass the application installer file to my friends. However, I have following questions.
If script or file doesn't have proper permission which my program is trying to access, will Python get an error?
Running some script or opening file will require the permission of root. So is there a possible option that will prompt the user for root(admin) password or run my application with root privilege?
Thanks
Try chmod 777 filname.py, this will give the file all rights for execution and editing. There are also other modes for chmod like 755, which will also work for your case.
I need to run the windows command "XCOPY" on remote machine.
I am using paramiko module to connect to remote machine and run, but I am getting error like invalid path even though the path is valid and same command works if I run on remote command prompt manually. But not possible through paramiko.
Can anybody help?
Regards,
Arun
May be you can get help from:
http://support.microsoft.com/kb/192808
hava a look.
I am working on a server with no X servers and trying to run a script that uses spynner module, which requires an X server. For this purpose, I want to run Xvfb.
I can run the script by calling it via xvfb-run, i.e.:
xvfb-run python2.6 try.py.
This works with no problem. However, I need to invoke Xvfb from within the script. For this purpose, I tried using subprocess as follows:
xvfb = subprocess.Popen(['Xvfb', ':99'])
After adding this piece of code to the beginning of the script, and trying to run the script as
python2.6 try.py
I get the message:
: cannot connect to X server
Is there something else I need to do? Thanks in advance.
For future visitors, it is worth mentioning that PyVirtualDisplay offers an abstraction over Xvfb to make it easy to use from Python.
you'll need to add:
import os
os.environ["DISPLAY"]=":99"
so that when it goes to open the connection to the X server it'll be able to find the Xvfb instance you've started