I’ve got a python script that’s being executed remotely. The final segment of this code is supposed to create an output file in the script’s directory (remote) for further reporting.
The script is being executed over ssh:
ssh -c blowfish remoteAddr python -u pythonScript.py $1 $2 $3
This allows arguments passed into the script (I’m using bash) to become inputs to the python script.
On the remoted end, my attempts to create an output file (.csv) have proven useless:
csvFile = open('results.csv','w')
csvFile.write(someResults)
csvFile.close()
returns an IOError (Errno 13): Permission denied ‘results.csv’. The error is marking my open as the culprit.
performing an ls -l on the directory the python is being executed on, I get:
-rwxr-xr-x 1 jmschen operations 5003 <dateTimeStamp> pythonScript.py
Which makes me think that I should have no problems with access. Also, I have tried the following:
os.chmod(<WherePythonScriptLives>,0777)
csvFile = open("results.csv","w")
csvFile.write(someResults)
csvFile.close()
This also produces the same error.
running this code locally (after sshing into the terminal) gives the same IOError; However, a python script that I created in the directory (test.py)
import os
f = open("results.csv","w")
f.write("Blah Blah Blah")
f.close()
works just fine. This makes me think that the fact we’re executing python remotely might be the issue?
Requirements:
- Python 2.4.3 on Unix (Can’t upgrade)
- No external modules/packages (not that I think we’d need them for this)
Can’t change theThis requirement is removed since the ssh call might be the culprit.ssh -c blowfish remoteAddr python -u pythonScript.py $1 $2 $3call
If I understand your question correctly…
I ran into a similar situation yesterday where php was meant to execute an external python script. I was mistaking my user permissions with php-user permissions. I had to used chmod() in php.
Through researching your question I discovered the Python equivalent. Try this:
This is much the same process I had with my php example. Please note, the
modedefault is octal, so if giving full permission, mode should be0777vs the terminal’s777.I hope this helps!
*Untested