I installed python27 , and also the latest version of apache.
in order to run a simple program by refering link
also edited the httpd.conf file also
but i accessed the folder localhost/cgi-bin displays the error
"Forbiden you don't have the permission to access this folder"
Changed the folder permission from properties of folder.
any other way to solve the problem.
So you have a cgi script named hello.py containing the code from the tutorial and installed in the cgi-bin directory as configured in the httpd.conf file?
If you browse to http://localhost/cgi-bin/ you will most likely see a HTTP 403 Forbidden response with text along the lines of:
You don't have permission to access /cgi-bin/ on this server.
You need to execute the actual cgi script, not the containing directory, so try browsing to http://localhost/cgi-bin/hello.py.
If that doesn't work, what changes did you make to httpd.conf? Have you installed the cgi script in the directory specified in the ScriptAlias /cgi-bin/ directive?
Related
I'm working on MAC application contains a command line tool.
The GUI (electron) using sudo prompt to run the command line tool written in Python.
Under Catalina, the app all needed permission to w/r for the protected directories like Desktop with no issue.
Needed permission request were added to plist and it is signed with list of entitlements.
All works well except accessing external hard drive. Any try to create folder or modifying its properties using chmod command for example return with permission denied.
Just for note, calling same command from terminal ends well with no issue
Any ideas how I can go over it?
How App can request Full disk access?
I built a Python application with Flask and run with Waitress server.
The app use local .csv files as the input data.
It can run well when running by command line. (ie. python webserver.py), I can load csv to read data, upload (to overwrite) the csv files.
But when I add it as a window's service (with nssm, or Window Resource Kit), my app can run, but the csv files only can be loaded by JS, not by the python.
It means, in service mode, if I load csv using js, It's ok, but when loading or uploading file (using python script) It returns "Internal Server Error".
My question is, how are running by command line and adding as Window's service different? How to make python script works with csv file when making it as service?
Any help is appreciated. Thank you so much.
This is the upload code.
#app.route('/uploadss', methods = ['GET', 'POST'])
def upload():
import os
print(request.files['file'])
if request.method=='POST':
file = request.files['file']
filenames = ['temperature.csv','inlet_clean_info.csv','log_data.csv','medium-term-temperature.csv']
if file.filename in filenames:
file.save(os.path.join(app.config['UPLOAD_FOLDER'], file.filename))
return 'file uploaded successfully'
else:
return 'filename is not acceptable'
and I have add waitress webserver as service with:
> -(nssm) nssm.exe install MyService. Then add python path and the executed python file.
> -(Window ResKit) instsrv.exe LNG c:\reskit\srvany.exe. Then add "Parameter" key in Regedit, add "Application" String to point to <python path> <executed path>
In both cases, it returns "Internal Server Error"
This is the Error message, the returned response
" 500
Internal Server Error Internal Server Error The
server encountered an internal error and was unable to complete your
request. Either the server is overloaded or there is an error in the
application. "
The primary differences when running an app as a service are around environment.
Some things specifically:
Which user the service is running as.
When you start it from the command line, it's likely running as your user account. Your user account is likely to have different permissions from the Windows system account. This tends to cause issues with accessing files more than, for example, opening a port for an HTTP server. There may be other permissions related problems.
Environment variables, including PATH.
When you're in a command shell, windows has a PATH variable that tells it where to look for executable files. So if you type python it looks for python.exe in the current folder, then it searches through the PATH variable until it finds python.exe
You also have other environment variables that can be defined such as TMP (temporary folder), etc.
When it's running as a service, it's generally running in a different user context, which will have different environment variables, both the %TMP% and PATH. So one thing that could be happening is that it's trying to run python.exe but there's no python.exe on the path for the service user.
HKCU Registry entry
If your app uses the registry, and uses the HKEY_CURRENT_USER tree, this is likely different when it's running as a service. (HKEY_CURRENT_MACHINE is likely the same).
The folder that the application starts in
When you run it from the command line, you generally start it in the current folder. This means that it's possible to use relative paths (e.g. .\images) instead of absolute paths (c:\website\images).
If you were to change to a different folder, then the .\images version may not work.
When a program runs as a service, it usually seems to start in C:\Windows\System32
So you could investigate whether using absolute paths works. Or you could investigate whether there's a way to specify the startup folder.
Another thing to check (possibly first) - look for the log file
Normally web servers write a log file on the server somewhere.
The 500 error would go to the user, but there'd be a more detailed error written to a log. So find where that log file should be and check it out. (It's possible that it's not where it should be, and that could be to do with permissions associated with the User the service is running as). If it is there, it may help track down the particular issue.
I am running XAMPP control panel 3.2.2 in order to have Apache and MySQL hosted, and I have correctly imported PyMySQL and cgi, which I have verified to be installed.
However, when I try and run a test script to make sure that everything is working together, it prints part of the program correctly, but not the other stuff. Images attached.
How do I fix this? I have tried Googling solutions but nothing to solve it has come up, and the python.exe location is definitely correct.
Modules verified
Program displayed
Test program
XAMPP running
Alright I fixed it, here is how I did it for anyone looking at this question:
Open the Apache httpd.conf configuration file from XAMPP
Locate the AddHandler block of code using CTRL-F
Where it says
AddHandler cgi-script .cgi .pl .asp
Add .py to the end of the list so it instead becomes:
AddHandler cgi-script .cgi .pl .asp .py
Save the file with .py appended onto it
Restart XAMPP and then launch the file from a web browser, where it should be working
I have 2 python env in my server. One path is /usr/bin and other one is the anaconda path as shown below. I am getting Permission denied error when I try executing a basic Python script on my Apache server. The python interpreter path in my .py file is as follows
#!/home/cloudera/anaconda3/bin
When this path is used, the apache server shows the error as shown below:
(13)Permission denied: exec of '/var/www/cgi-bin/abc.py' failed, referer:
When my python interpreter path in .py is changed to i.e #!/usr/bin it works well.
The problem is I have installed all my packages in /home/cloudera/anaconda3/bin
I tried setting this path to be accessible to execute in apache server by adding the below line of code in /etc/httpd/conf/httpd.conf file as follows
<Directory "/home/cloudera/anaconda3/bin/">
AllowOverride None
Options ExecCGI
AddHandler cgi-script .py
#None
Order allow,deny
Allow from all
</Directory>
I still get Permission Denied. It still does not work. I am new to cgi, any help would be really grateful. Thanks in advance.
Admittedly I've completely missed the fact that the interpret was specified as directory and the actual binary file as pointed out by Jean-François Fabre. That would indeed cause the same error. But since the OP fixed that and still got the same error, I am undeleting the answer extended as requested.
Also come to think of it, it may be more of a Server Fault question as it would appear.
This error (13: EACCES) is raised by and propagated from the OS.
HTTPd servers usually employ privilege separation and once bound to a reserved port drop their EUID to an unprivileged user. Usually a dedicate one or nobody (on my system it would be user apache, group apache). You should be able to find these in your httpd.conf under User and Group resp.
Make sure this user has access and can execute the binary you're calling.
Give you've fixed the interpreted (and the file would execute on its own). Go find your httpd.conf file (I think different distros may package it differently, on mine it would reside here: /etc/httpd/httpd.conf). You will find User and Group entries there. You must be able to access and execute the script (incl. the interpreter) as this user, because that's how Apache will try to call it. I.e. this user (or group) must be able to access this file (along the complete path) and execute it. If for instance /home/cloudera/ us restricted to (0700: rwx------) and owned by user other then the one listed int your httpd.conf (very likely), OS would prevent your Apache user to access and execute the file resulting in EACCES error you are seeing. The easiest might be to become that user and see how far your access goes, but you'd need to temporarily tweak few bits for that as the Apache account likely is locked and has not shell set (or rather /bin/false as shell).
One more thing, but I hope it's not as obvious as that. The corresponding user must have execute permission on the script itself.
I am new to python cgi programming. I have installed apache 2.2 server on linux mint and I have my html form in var/www folder which is being displayed properly. Action to the form is a cgi script that I've put in the folder /usr/lib/cgi-bin. But on submit, it says "The requested URL /usr/lib/cgi-bin/file.cgi as not found on this server." Does anyone know the fix for this?
What is the name of your Python program? Is it /usr/lib/cgi-bin/file.cgi?
What are the rights of this file? Can it be read by apache? Can it be executed?
Is first line with #!/usr/bin/env python or similar good? Make sure that this file can be run from command line (ie. shebang is good)
Does apache receive request with that file? Look at apache logs, especially error.log and access.log (probably in /var/log/apache)
Make sure you have enabled ExecCGI for /usr/lib/cgi-bin/ directory in Apache configuration. For examples see at: http://opensuse.swerdna.org/suseapache.html. You can also use ScriptAlias directive.