How to solve internal error 500 for python on Xampp - python

I am getting this error:
Server error!
The server encountered an internal error and was unable to complete your request.
Error message: End of script output before headers: python.py
If you think this is a server error, please contact the webmaster.
Error 500
192.168.64.2 Apache/2.4.41 (Unix) OpenSSL/1.1.1d PHP/7.4.1 mod_perl/2.0.8-dev Perl/v5.16.3
I have done the following:
Added .py to Addhandler in httpd.conf
I have also installed pip and pymysql.
I am using python 3.8.3
I have also have the permissions set to chmod 755
have also tried chmod 755, +x but no luck I have also checked the error logs but no clear problem
In the error logs it says: End of script output before headers: python.py
and
(2)No such file or directory: exec of '/opt/lampp/htdocs/11-python/python.py' failed: /opt/lampp/htdocs/11-python/python.py
btw I am using Mac
Heres my code:
#!/usr/bin/local/env python3
print ('Content-type: text/html\r\n')
print ('\r\n')
print ()
print ('<html>')
print ('<head>')
print ('</head>')
print ('<body>')
print ('Hello Python')
print ('</body>')
print ('</html>')

Related

Error while running python with xammp server

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.

Trying to start appium server from the command line but keep getting this error

C:\Users\13024\PycharmProjects\UltraShop_Clean
Encountered internal error running command: Error: Could not sign with default certificate. Original error Command 'C:\Program Files\Java\jdk1.8.0_251\bin\bin\java.exe' not found. Is it installed?
[debug] [W3C] at ADB.signWithDef
java is installed and working it does have two \bins that do not exist
An unknown server-side error occurred while processing the command. Original error:
Could not sign with default certificate. Original error Command
'C:\Android\Studio\jre\bin\bin\java.exe' not found. Is it installed?
my system envs:
Removing the /bin from my java env Var and restarting computer worked.

linux apache python cgi error: failed to get random numbers to initialize Python

My old CentOS 5 apache server can run Perl script CGI without any problem.
# cat t1.cgi
#!/usr/local/bin/perl
use CGI;
my $cgi = CGI->new();
print $cgi->header;
print "Test\n";
# GET HTTP://www.example.com/cgi/t1.cgi
Test
python scripts can be run under shell without any problem:
# cat t2.cgi
#!/usr/local/bin/python3
print("Content-Type: text/html\n")
print("hello!")
# python3 t2.cgi
Content-Type: text/html
hello!
but failed as a python cgi script:
# GET http://www.example.com/cgi/t2.cgi
<HTML>
<HEAD><TITLE>An Error Occurred</TITLE></HEAD>
<BODY>
<H1>An Error Occurred</H1>
500 Internal Server Error
</BODY>
</HTML>
apache error logs show the error was:
Fatal Python error: _Py_HashRandomization_Init: failed to get random numbers to initialize Python
Python runtime state: preinitialized
Premature end of script headers: t2.cgi
any idea will be appreciated!
fixed it by
mknod -m 444 /dev/random
chmod 444 /dev/urandom
my old centos don't have /dev/random, and the default file mode for urandom was 600, read only by root.

Error sending email by calling a bash script

My sendmail.sh script on Raspbian OS is able to successfully send an email. But when it's called from a python script, I get a "mail: can not send message: process exited with non zero status" error message. I have verified that ssmtp is configured correctly by running sendmail.sh by hand.
sendmail.sh
#!/bin/bash
echo "test" | mail -s "test msg" myemailaddress
permissions on sendmail.sh are 777. sendmail.sh and sendmail.py are in the same directory.
sendmail.py
import os
import subprocess
subprocess.call(['./sendmail.sh'])
The command I use to run the python - sudo python sendmail.py.
I don't understand why the error occurs. Clearly, python is calling sendmail.sh and the script has correct permissions set on it. If run sendmail.sh by hand, the mail is sent correctly.
The root cause is the error message given by ssmtp's mail, which is most unhelpful.
A quick googling it reveals http://www.raspberrypi.org/forums/viewtopic.php?t=46218&p=386393 which says the following:
Try running the command with an additional -d parameter to get some more debug information to help determine the cause of the issue:
echo "Test" | mail -d -s "Test" myemail#mydomain.co.uk
<...>
I checked my error logs, and noticed this:
<date time> raspberrypi sSMTP[3477]: <a bunch of messages, including the error showing the root cause>
You can try this command:
os.system('./sendmail.sh')

Running python LAMPP (linux) via apache

I have a file: test.py
Permissions on this file are set to 777, I am attempting to run the following script:
#!/usr/lib/python2.7
print("Content-Type: text/html\n")
print("test")
I receive the following error:
The server encountered an internal error and was unable to complete your request.
Error message:
End of script output before headers: test.py
If you think this is a server error, please contact the webmaster.
Error 500
Python is installed:
$ python --version
>> Python 2.7.4
Solved the problem, you need to use the location of the python interpreter in the first line of the code which can be found by running the following script in the python interpreter (can be invoked by typing python into the terminal):
import sys; sys.executable;

Categories

Resources