run cgi file from xampp localhost on mac osx - python

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?

Related

Can´t execute python file in browser with XAMPP: (13)Permission denied [duplicate]

This question already has answers here:
"End of script output before headers" error in Apache
(13 answers)
Closed 3 years ago.
I want to run my chatbot in the browser (chatbot code is here)
I have xampp installed on a mac.
When I try to output "Hello World" I get the error:
End of script output before headers: text.py
In the error_log of Xampp is:
(13) Permission denied: exec of '/Applications/XAMPP/xamppfiles/htdocs/chatbot/text.py' failed: /Applications/XAMPP/xamppfiles/htdocs/chatbot/text.py, referer: http: // localhost / chatbot /
[Tue May 14 13:52:48:593860 2019] [cgi: error] [pid 34638] [client :: 1: 56104] End of script output before headers: text.py, referer: http: // localhost / chatbot /
But I have given all the folders the right read and write and also restarted the Xampp.
I also changed the httpd.config file so that i can run python code on xampp. (I changed the Handler like this: AddHandler cgi-script .cgi .py)
This ist the code that should run in the browser(simply print hello world)
#!/usr/bin/python3.7
print("Content-type: text/html")
print()
print("Hello, world!")
I had several issues like this with XAMPP. Did you try MAMP instead?

I get unrecognized option '--wsgi-file' when trying to run uwsgi

I'm setting up a test Python App on a Ubuntu server. I've installed Nginx, Python, and uWSGI. Nginx is able to host static files, but I get the error "uWSGI Error Python application not found" when I try to access a Python app.
I have created a file named "app.py", which is a simple "Hello World" app. This file is added to the same directory as the static HTML file. The static file comes up, so Nginx appears to be working.
When I tried to access the Python app, I got the error "uWSGI Error Python application not found". I searched for this error and one recommendation is from https://uwsgi-docs.readthedocs.io/en/latest/tutorials/Django_and_nginx.html. It mentions I had to run the following command:
uwsgi --http :8000 --wsgi-file test.py
I changed the port number and file name to what I have on my server. But I get the error:
uwsgi: unrecognized option '--wsgi-file'
I googled this error and a link mentioned I would have to install the python plugin: uwsgi options --wsgi-file and --module not recognized
But when I did the commands in this URL, it says I already have the newest version.
If I just type uwsgi on the command prompt, it would give me the message:
* WARNING: you are running uWSGI without its master process manager *
your memory page size is 4096 bytes
The -s/--socket option is missing and stdin is not a socket.
I was wondering if there are any items (e.g. programs, configuration settings) I need to look at to get uwsgi running and the web server able to host Python apps?
You can try running uwsgi by explicitly stating the plugin you want to load:
uwsgi --http-socket :8000 --plugin python --wsgi-file test.py

Python Internal Server Error

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!!!!

Python webscript will not run - generates 403 error

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.

logfile causes permission error in django application deployed on apache

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.

Categories

Resources