0

I have a web server and my cgi-bin is on 0755, and my script called return.py is also 0755. And when my script is just this

#!/usr/bin/perl

import cgi
import json


print "Content-type: text/plain\n\n";
print "testing...\n";

And I go to the web page I see testing... as I should, but when I add any of this to my script

form = cgi.FieldStorage()

param = form.getvalue("param")

if param:
    json.dumps({'success': True, 'message':  param })
else:
    json.dumps({'success': False, 'message':  'did not receive parameter' })

I get a 500 Internal Server Error, and Im not sure why, I have the correct permissions set, and the python is running because it works when I don't add the stuff above? Is there something wrong with my above code? What else could be causing this issue?

BY THE WAY the above code is because I am making a POST to this and what to return the value posted. Just a simple test case, but I can't get it to work?

Ive gone through this check list, of what I could check, and it all worked https://encodable.com/internal_server_error/

Thanks for the help in advance. :)

EDIT

here are error logs

[Tue Jun 23 01:35:38.661161 2015] [authz_core:error] [pid 874653] [client 173.34------:51484] AH01630: client denied by server configuration: /home/spencer/public_html/.htaccess
[Tue Jun 23 01:35:38.426745 2015] [access_compat:error] [pid 874653] [client 173.34-----:51484] AH01797: client denied by server configuration: /home/spencer/public_html/error_log
6
  • 1
    Check the log, there might be some error in code. Commented Jun 23, 2015 at 7:02
  • @Lafada not sure how to access or if I do have access to it? how can I find out? Commented Jun 23, 2015 at 7:03
  • @Lafada it says "client denied by server configuration: " Commented Jun 23, 2015 at 7:06
  • Please add your logs in question, that will help to understand your problem. Commented Jun 23, 2015 at 7:13
  • BTW, you do not print json results Commented Jun 23, 2015 at 7:49

1 Answer 1

1

Just change the shebang and it should work

#!/usr/bin/perl
import cgi
import json
print "Content-type: text/plain\n\n";
print "testing...\n";

and assuming u save it as test.py works then u add below part

#!/usr/bin/perl
import cgi
import json
print "Content-type: text/plain\n\n";
print "testing...\n";
form = cgi.FieldStorage()
param = form.getvalue("param")
if param:
    json.dumps({'success': True, 'message':  param })
else:
    json.dumps({'success': False, 'message':  'did not receive parameter' })

it gives server error

Then change the shebang to

#!/usr/bin/python

And it works .....put correct shebang and life is easy

Sign up to request clarification or add additional context in comments.

1 Comment

Okay now it works, if I change it to #!/usr/bin/python but why? And I still need print "Content-type: text/plain\n\n"; line above the all, why does that need to be there?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.