LoginSignup
0
0

More than 5 years have passed since last update.

MAMPでPython実行時の「premature end of script headers」

Posted at

※開発環境はMacです。
MAMPフォルダのcgi-binフォルダにhello.pyを作成し、
ターミナルにて
$ cd /Applications/MAMP/cgi-bin
$ chmod +x hello.py

と打ち込むことで実行権限を与え、いざpythonを書いていこうという時に現れた「premature end of script headers」

よくよくエラーコードを読んでみると、
「SyntaxError: Non-ASCII character '\xe5' in file /Applications/MAMP/cgi-bin/hello.py on line 18, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details」
と書かれており、どうやらencodingでトラブっているらしい。

と思ってコードを見直すと、18行目にそういえば日本語を含むコメントを入れていたことに気づく。


#!/usr/bin/python --

print 'Content-type: text/html'
print ''
省略
L18 #日本語を含む文字列

#コメントの日本語を取り除いたらエラーは解決しました。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0