I am trying to run a python (.py) script on my website.
Whenever I direct my browser to http://mydomain.co.uk/cgi-bin/index.py I get a 403 error.
I have checked, and everyone has execute permissions.
I have checked the error log, and got this:
[Thu May 10 13:17:03 2012] [error] [client 82.132.248.44] client denied by server configuration: /home/liamwli2/public_html/cgi-bin/index.py
I am using a shared hosting package.
Can anyone give me a solution? Thanks.
Related
I'm new to Python Web Development and I have written the following code and uploaded into the root of my server (public_html) folder:
import web
urls = ('/','index')
app = web.application(urls, globals())
class index:
def GET(self):
greeting = "Hello World"
return greeting
app.run()
My .htaccess file is:
AddType text/html py
AddHandler cgi-script .py .cgi
When I open my site, I get the following error:
Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator, webmaster#example.com and inform them of the time the error occurred, and anything you might have done that may have caused the error.
More information about this error may be available in the server error log.
Additionally, a 500 Internal Server Error error was encountered while trying to use an ErrorDocument to handle the request.
My cPanel Error Log shows:
[Thu Jul 30 10:44:42 2015] [error] [client 1.1.1.1] client denied by server configuration: /home/user/public_html/.htaccess
[Thu Jul 30 10:36:53 2015] [error] [client 1.1.1.1] attempt to invoke directory as script: /home/user/public_html/cgi-bin/, referer: http://example.com/
Most of the places I searched for said that the .py file should be given permission 755. I did the same and in addition, even gave 755 permission to .htaccess file.
What may be the probable solution?
I believe its neither issue with py or .htaccess file permissions, its all about provide access to the files under .htaccess in the configuration section... check that out!!!!
I am developing a Flask application on CentOS 6.6 on Apache and Mysql. It is modified from The Flask Megatutorial. I am able to create normally the database, however when I try to access it from my browser I get 500 internal server error and this in the error_log file:
content type: text/html
<h1>Hello world!</h1>
[Sun May 03 18:39:53 2015] [error] [client my.ip.add.res] (104)Connection reset by peer: mod_fcgid: error reading data from FastCGI server
[Sun May 03 18:39:53 2015] [error] [client my.ip.add.res] Premature end of script headers: runp-mysql.fcgi
This is after I've edited down the runp-mysql.fcgi file to this:
#!flask/bin/python
#encoding=UTF-8
#import os
print "content type: text/html\n\n"
print ""
print "<h1>Hello world!</h1>"
Running this from the command line completes correctly.
My httpd.conf file ends with this:
FcgidIPCDir /tmp
AddHandler fcgid-script .fcgi
<VirtualHost *:80>
DocumentRoot /home/apps/my_app/app/static
Alias /static /home/apps/my_app/app/static
ScriptAlias / /home/apps/my_app/runp-mysql.fcgi/
</VirtualHost>
I was doing the same and a major issue was the permissions on the file. make sure it is executable and not read only.
Also I do not think that the runp-mysql.fcgi is where you want to do your printing. It should be in the views file. This is where you should have the connection to the your mysql database then start the wscgi server.
This is a very loose answer based on my actual problem and I am only uploading it in case someone else follows the same tutorial and also has a problem with deployment.
The gist of it is that under the python version I used (2.7) for deployment the flipflop module did not work and I had to use flup instead. For anyone getting the same error - try it, it might work.
I am trying to have a python script execute on the click of an image but whenever the python script gets called it always throws a 500 Internal Server Error? Here is the text from the log
[Sun Feb 15 20:31:04 2015] [error] (2)No such file or directory: exec of '/var/www/forward.py' failed
[Sun Feb 15 20:31:04 2015] [error] [client 192.168.15.51] Premature end of script headers: forward.py, referer: http://192.168.15.76/Testing.html
I don't understand why it is saying Premature end of script header? I can execute a basic python script that just prints an html header or text. The file I am trying to execute just has some basic wiringPi code that executes fine from the sudo python forward.py command?
EDIT
This is the script I'm trying to execute:
#!/usr/bin/python
import time
import wiringpi2 as wiringpi
wiringpi.wiringPiSetupPhys()
wiringpi.pinMode(40, 1)
wiringpi.digitalWrite(40, 1)
time.sleep(2)
wiringpi.digitalWrite(40, 0)
wiringpi.pinMode(40, 0)
Things to check:
Make sure the script is executable (chmod +x forward.py) and that it has a she-bang line (e.g. #!/usr/bin/env python).
Make sure the script's owner & group match up with what user apache is running as.
Try running the script from the command line as the apache user. I see that you're testing it with sudo. Does it really need sudo? If so whatever user is running as apache will also need sudoers access.
Since it looks like you're using CGI, try adding: import cgitb; cgitb.enable(); to the top of your script. This will catch any exceptions and return it as a response instead of causing the script to die.
In addition to #lost-theory's recommendations, I would also check to make sure:
You have executable permission on the script.
Apache has permission to access the folder/file of the script. For example:
<Directory /path/to/your/dir>
<Files *>
Order allow,deny
Allow from all
Require all granted
</Files>
</Directory>
i am a complete noob to python scripts. I am following this tutorial to do some iOS stuff. This includes python cgi script integration as well.
I have successfully made the cgi file but am not able to run it.
File path is: /Applications/XAMPP/xamppfiles/cgi-bin/payment-test.cgi
In browser I run the file as: http://localhost/cgi-bin/payment-test.cgi
I get the following error:
Server error!
The server encountered an internal error and was unable to complete your request.
Error message:
Premature end of script headers: payment-test.cgi
If you think this is a server error, please contact the webmaster.
Error 500
localhost
Sat Oct 11 12:24:29 2014
Apache/2.2.14 (Unix) DAV/2 mod_ssl/2.2.14 OpenSSL/0.9.8l PHP/5.3.1 mod_perl/2.0.4 Perl/v5.10.1
I have modified httpd.conf by following this link.
Where am I getting wrong? How do I solve this?
I have deployed a Django 1.3.1 app on apache2 in my machine using mod_wsgi.I used to log some values in the app using python logging module and these were written to a mylog.txt file in the application base directory.However I deleted this file and commented out every log() call in my code.In the django standalone server the app runs without any problem.But when I start the app in apache,I get this apache log entry
[Sat Mar 31 09:34:40 2012] [error] [client 127.0.0.1] TemplateSyntaxError: Caught IOError while rendering: [Errno 13] Permission denied: '/home/me/dev/python/django/myapp/mylog.txt'
I cannot understand why this happens ,since I commented out every log related line in the code and even the variable which tells the logfile's name in settings.py
I tried clearing the cache..but even that didn't help
can someone help me figure this out?
The module details are as below
Apache/2.0.63 (Unix) DAV/2 mod_wsgi/3.3 Python/2.6.5 Server at 127.0.0.1 Port 80
what are the unix/linux permissions on your mylog.txt file?
ls -la /home/me/dev/python/django/myapp/mylog.txt should show the unix/linux perms. Can you paste the results of this command? (update it in your question above if possible)
Apache2 user on your system (depending on which linux distro of if you use Mac) are most likely 'www-data' or 'http'. You will need to make sure that mylog.txt has the correct unix/linux owner and the correct permissions mode so that apache2 can write into this log file.
I also met this problem in Webpy+Apache. And I changed the Apache logs directory owner to Apache user then the problem solved.