Getting python to work, Internal Server Error

后端 未结 12 1561
無奈伤痛
無奈伤痛 2021-02-08 11:07

I\'m trying to get Python scripts, called from a web browser, to work. I keep getting the error:

500 Internal Server Error

When I check my err

相关标签:
12条回答
  • 2021-02-08 11:51

    If you have configured Apaches httpd file correctly then you might be getting this error for following two reasons.Make sure these are correct.

    1. Include '#!/usr/bin/python' or '#!C:/Python27/python' or accordingly in your script as first line.
    2. Make sure there is space after print "Content-type: text/html" ie.
      print "Content-type: text/html\n\n";
      Hope this helps!!
    0 讨论(0)
  • 2021-02-08 11:52

    do you have something like this at the top before you print anything else?

    print "Content-type: text/html\n"
    

    If you already have this, then post your code.

    0 讨论(0)
  • 2021-02-08 11:53

    OK last guess:

    Trying changing that shebang line to:

    #!/usr/bin/env python
    

    or

    #!/usr/bin/local/env python
    

    It would also be helpful to know your platform / hosting provider.

    0 讨论(0)
  • 2021-02-08 11:55

    You can also get some of this same foolishness if you have DOS style end of lines on a linux web server. (That just chewed up about two hours of my morning today.) Off to update my vim.rc on this windows box that I need to use.

    0 讨论(0)
  • 2021-02-08 11:58

    This ended up being a dos2unix issue for me. Ran dos2unix test.py test.py and it worked. The \r\n combinations were the problem. Had to yum install dos2unix to get it installed.

    0 讨论(0)
  • 2021-02-08 12:07

    This is the exact behavior you would get if your Python script does not have the executable permission set.

    Try:

    chmod a+x foo.py
    

    (where foo.py is your script name).

    See the Apache tutorial for more information.

    0 讨论(0)
提交回复
热议问题