2016-05-13 3 views
0

私はApache2 Webサーバーで単純なPythonスクリプトを実行しようとしています。しかし、私はエラーの後になる。助けてください、私はそれを取得しません。ありがとうございました。Apache2 + Python

ファイル:

print('Content-Type: text/html; charset=utf-8\n') 
print() 
print("Hello, World!") 

ブラウザエラー

Internal Server Error 

The server encountered an internal error or misconfiguration and was unable to complete your request. 

Please contact the server administrator at [email protected] 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. 

エラー・ログ・

[Fri May 13 13:35:05.520836 2016] [cgi:error] [pid 12967] [client ::1:41077] AH01215: (8)Exec format error: exec of '/var/www/html/index.py' failed 
[Fri May 13 13:35:05.522775 2016] [cgi:error] [pid 12967] [client ::1:41077] End of script output before headers: index.py 
+0

これは役立つかもしれません:http://serverfault.com/questions/107952/premature-end-of-script-and-exec-format-error – sebastian

+0

あなたは手でスクリプトを実行できますか?それを実行します? –

+0

CGIとしてのPythonの実行は1990年代です。しかし、本当にこのルートに行きたい場合は、ヘッダーの後に空白行( '\ n')がなければならないことに注意してください。 – e4c5

答えて

0

私は簡単に実行することができますこのファイルは、端末のpython index.pyを介して表示されます。それは次のようになります。

Content-Type: text/html; charset=utf-8 

() 
Hello, World! 

私はPython 2.7を使用しているようです。 (python -v)です。 "ヘッダーの後に空白行( '\ n')がなければならないことに注意してください。"それはどういう意味ですか?コードの例を教えてください。 python 2.7で

0

印刷自体は、印刷()を使用するようにコードを変更する必要機能ではありません:これは動作するはず

print "Content-Type: text/html; charset=utf-8\n" 
print "" 
print "Hello, World!" 

+0

同じエラーです。 – Bebop

+0

ls -ldを実行してスクリプトに実行権限があるかどうか確認してください。また、上記のコードに変更した後も同じエラーを表示するエラーログですか? – ajays20078

+0

私はpiユーザーで実行するため、私はwww-dataについてはわかりません。 -rwxr-xr-x 1 pi www-data 81 Mai 13 17:34 index.pyエラーログは変わりません。 – Bebop