简体   繁体   中英

Python code displays Error 500 - Internal Server Error

1) A python code works properly in local console. 2) I transfer this code via ftp to the server, run it in web and it doesn't work displaying Internal Server Error. 3) I open and edit this code directly from the server via cpanel and save it without any change, not even an indentation change. Then the code starts working properly in the web.

#!/usr/bin/python
# -*- coding: utf-8 -*-
def main():
    print "hello"
if __name__ == '__main__':
    print "Content-type: text/html\n\n"
    main()

Server log: End of script output before headers: x.py

htcaccess:

Options +ExecCGI
Options -Indexes
Header set X-Frame-Options DENY
Header set Access-Control-Allow-Origin *
AddHandler py-bin .py
AddHandler cgi-script .py

Can someone explain what may be wrong with the server?

Try changing your #!/usr/bin/python by #!/usr/bin/env python or #!/usr/bin/local/env python

Or maybe your script needs some permissions

如何运行Python脚本

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM