My cgi file:
#!/bin/sh -f
source /Users/sfma/sastbx/build/setpaths_all.sh
python processQuery.py
Then "Internal Server Error" arises. I checked the error_log, and it says:
[Thu Jun 23 15:02:39.809441 2016] [cgi:error] [pid 1327] [client ::1:52131] AH01215: /Users/sfma/sastbx/build/bin/libtbx.path_utility: line 63: /Users/sfma/sastbx/build/../../Library/Enthought/Canopy_64bit/User/bin/python: Permission denied: /Library/WebServer/CGI-Executables/web.cgi, referer: http://localhost/modelRetrieval/query.html
Remove the source statement, it works fine. But I need to source this file for further use.
Edit
According to the error message, I think the error may be due to the python permission.
#!/bin/sh -f
#python processQuery.py #this works fine
/Users/sfma/Library/Enthought/Canopy_64bit/User/bin/python processQuery.py #this does not work. Permission denied.
This really puzzles me because /Users/sfma/Library/Enthought/Canopy_64bit/User/bin/python is exactly the python I'm using:
$which python
/Users/sfma/Library/Enthought/Canopy_64bit/User/bin/python
I finally solved this problem.
Since python works fine while /Users/sfma/Library/Enthought/canopy_64bit/User/bin/python leads to a problem, I hard coded some variables in files libtbx.path_utility and sastbx.python to "python" instead of what they used to be: "/Users/sfma/sastbx/build/../../Library/Enthought/canopy_64bit/User/bin/python"
Update
The reason why /Users/sfma/Library/Enthought/Canopy_64bit/User/bin/python is permission denied is that _www is now allowed to visit my Library folder. Check this. After making that directory available to all, this problem is finally solved.
Related
I am new in running python with xammp server. I have done all the required setup to run python in xammp server by following this link Running Python scripts with Xampp. While trying to running my code i always get an error.
**Internal Server Error The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator at postmaster#localhost to
inform them of the time this error occurred, and the actions you
performed just before this error.
More information about this error may be available in the server error
log.**
My error log says this:
[Tue Jan 19 10:29:34.529875 2021] [cgi:error] [pid 11652:tid 1860] [client ::1:50570] malformed header from script 'python.py': Bad header: Hello World
i am attaching the code for my file too.
#! C:\Users\"UserName"\AppData\Local\Programs\Python\Python39\python.exe
print("Content-Type: text/html\n\n")
import cgi
print("Hello Python")
i have tried everything i could to search for the solution but nothing is helping. Please help me finding a solution. Thank you
Update the \n\n to use a carriage return (\r\n\r\n), and add another in.
This should make your HTTP headers valid, as they may not be terminating correctly.
Edit: You can also try multi-line print instructions such as
print "Content-type: text/html"
print ""
This is interpreting the body as the header (never terminated) so terminating this correctly should fix it.
I have a small service written in Python 3 which uses pysftp:
with pysftp.Connection(
host=host,
username=connection_data["user"],
port=connection_data["port"], log=log_file, cnopts=cnopts
) as srv:
…
and when I run it (python3 pythonprog.py) I get the following error:
PermissionError: [Errno 13] Permission denied: '/mydisk/folder/logs/pysftp-20181127-231208.log'
Obviously, I don't get this error if I run it with sudo python3 pythonprog.py.
I checked the permissions for this folder:
ls -l
drwxrwxrwx+ 2 myuser myuser 4096 Nov 27 22:38 logs
I also changed ACL with setfacl. Basically, whatever I do the error is still there. How can I grant this permission?
The service is running as someone -- that someone needs permission to write to that file or folder. This is not a code problem, its a permission problem. sudo is not the solution to running the code. I'm taking it that it is running as you? Can you write to that file/folder?
I am calling a python script through an ajax call
$.ajax({
url: "http://localhost/username/test.py",
type: "post",
data: JSON.stringify({'param':{"hello":"world"}}),
dataType: "json",
success: function(response) {
console.log(response);
},
error: function(error) {
console.log(error);
}
});
The python script kicks off (have set up the conf files and have an apache server running) but then the python script is supposed to loop through a bunch of subprocess calls calling various shell files. Something like this:
for line in reader:
var=line["A"]
var2=var[:-4]
var3=line["B"]
print(var2)
subprocess.call(["sh","dummy.sh",var,var2,var3])
The same python scripts works fine in terminal. But when I run through the web browser, I get permission a 500 error in the browser. Going into the apache logs, shows me its running into a permission error
[Thu Jul 23 18:13:55.958161 2015] [cgi:error] [pid 19878] [client ::1:54132] AH01215: dummy.sh: line 37: inputFile.xml: Permission denied, referer: http://localhost/username/
How do I pass permissions? or am I doing something completely wrong here?
When you run the python script at the terminal, it runs as a process with your user ID, I assume?
If you can open the input file by doing this, then it is most likely a permission issue.
The apache process just isn't privileged enough to open the file.
I'd suggest:
Check the owner and permission of the file - make sure it is readable by the Apache process userID. This requires the file to at least have read permission, ie. -rw-r--r-- (chmod 644).
Also don't forget the directory path permission and/or ownership.
eg. if the file is in /home/foo/bar/inputFile.xml, you need to check that the whole path /home/foo/bar is accessible by the Apache user. This requires at least drwx--x--x (chmod 711) on the directories.
Thanks Maelstrom, Revolt and rici. inputFile.xml is actually created within dummy.sh and then other steps within dummy.sh operate on inputFile.xml. I also anticipate that since I have already given other files in the folder 755 access, its these new formed xml files that are restricted. How do I ensure that all files created by dummy.sh have enough permissions that they can be executed upon? Thanks a lot.
When building with Maven from a Cygwin shell (bash on Windows via Cygwin), the path to /usr/bin is not resolving properly.
Let me explain. Cygwin comes with Python, which is accessible as a symlink from /usr/bin. This symlink should be accessible to Maven, because its location is in the PATH environment variable. Cygwin adds /usr/bin to the PATH environment variable. However, Maven is unable to find Python. E.g.
[ERROR] Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.2.1:exec (default) on project cloud-devcloud: Command execution failed. Cannot run program "python" (in directory "C:\cygwin\home\myuser\incubator-cloudstack\tools\devcloud"): CreateProcess error=2, The system cannot find the file specified -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
But Python is there:
$ which python
/usr/bin/python
Albeit as a symlink.
$ ls -al /usr/bin/python
lrwxrwxrwx 1 donall Domain Users 13 Sep 19 11:38 /usr/bin/python -> python2.6.exe
Is the issue that Python is a symlink? Or that Maven cannot access files in /usr/bin?
It seems like maven is running as a regular Windows-native application, not a "cygwin-aware application" (if such thing exists :-) )
This is indicated by the path used internally, which is printed in the log: C:\cygwin\home\myuser\incubator-cloudstack\tools\devcloud
For this reason the call from Maven will not recognize the cygwin path when locating the python executable. One possible solution is to add the directory containing python.exe to the system PATH (which means, the Windows PATH variable)
I'm working with web.py and for some reason I am getting the following error:
[Thu Sep 29 13:47:20 2011] [error] [client 64.8.210.120] File "/usr/lib/python2.6/site-packages/web.py-0.36-py2.6.egg/web/db.py", line 975, in __init__
[Thu Sep 29 13:47:20 2011] [error] [client 64.8.210.120] import MySQLdb as db
[Thu Sep 29 13:47:20 2011] [error] [client 64.8.210.120] ImportError: No module named MySQLdb
Here is my sys.path, in case that's the culprit? I see the.egg, though, so I don't know. Thoughts?
['', '/usr/lib/python2.6/site-packages/Bravo-1.7.2-py2.6.egg',
'/usr/lib/python2.6/site-packages/Twisted-11.0.0-py2.6-linux-i686.egg',
'/usr/lib/python2.6/site-packages/construct-2.04-py2.6.egg',
'/usr/lib/python2.6/site-packages/zope.interface-3.7.0-py2.6-linux-i686.egg', '/usr/lib/python2.6/site-packages/web.py-0.36-py2.6.egg',
'/usr/lib/python2.6/site-packages/MySQL_python-1.2.3-py2.6-linux-i686.egg',
'/usr/lib/python2.6/site-packages/setuptools-0.6c12dev_r88846-py2.6.egg',
'/usr/lib/python26.zip', '/usr/lib/python2.6', '/usr/lib/python2.6/plat-linux2',
'/usr/lib/python2.6/lib-tk', '/usr/lib/python2.6/lib-old', '/usr/lib/python2.6/lib-dynload', '/usr/lib/python2.6/site-packages',
'/usr/lib/python2.6/site-packages/PIL']
Here are the contents of the 2.6 site-packages directory:
[root#xxxx ~]# locate *.egg
/root/MySQL-python-1.2.3/dist/MySQL_python-1.2.3-py2.6-linux-i686.egg
/usr/lib/python2.4/site-packages/errorhandler-1.1.1-py2.4.egg
/usr/lib/python2.4/site-packages/setuptools-0.6c11-py2.4.egg
/usr/lib/python2.4/site-packages/xlrd-0.7.1-py2.4.egg
/usr/lib/python2.4/site-packages/xlutils-1.4.1-py2.4.egg
/usr/lib/python2.4/site-packages/xlutils-1.4.1-py2.5.egg
/usr/lib/python2.4/site-packages/xlwt-0.7.2-py2.4.egg
/usr/lib/python2.6/site-packages/Bravo-1.7.2-py2.6.egg
/usr/lib/python2.6/site-packages/MySQL_python-1.2.3-py2.6-linux-i686.egg
/usr/lib/python2.6/site-packages/Twisted-11.0.0-py2.6-linux-i686.egg
/usr/lib/python2.6/site-packages/construct-2.04-py2.6.egg
/usr/lib/python2.6/site-packages/setuptools-0.6c11-py2.6.egg
/usr/lib/python2.6/site-packages/setuptools-0.6c12dev_r88846-py2.6.egg
/usr/lib/python2.6/site-packages/web.py-0.36-py2.6.egg
/usr/lib/python2.6/site-packages/zope.interface-3.7.0-py2.6-linux-i686.egg
If I open python (either 2.4 or 2.6), I am able to import MySQLdb with no problem.
Thanks,
Tom
At the bottom of your bashrc (usually in /etc/bashrc) file put this (or just update the PYTHONPATH env variable to include /usr/lib/python2.6/site-packages):
if [ $PYTHONPATH ]
then
export PYTHONPATH=$PYTHONPATH:/usr/lib/python2.6/:/usr/lib/python2.6/site-packages/
else
export PYTHONPATH=/usr/lib/python2.6/:/usr/lib/python2.6/site-packages/
fi
Or, for the specific user that is running the script, put the above in /home/[USER_RUNNING_SCRIPT]/.bashrc.
Then source the file:
$ source ~/.bashrc
# or
# source /etc/bashrc
You can download mysqldb at : http://sourceforge.net/projects/mysql-python/
Try writing a simple page to show the sys.path as it exists from within the web server execution environment. Not sure if that's what you're showing when you show your sys.path in your question or if you ran that interactively from your login. Chances are the userid that the http server is running under has a different environment set up from what you have as a regular user.