2012-05-19 4 views
4

저는 hostgator를 사용하고 있으며 Python이 지원된다는 것을 맹세하지만 아직 Python 스크립트를보고 있습니다.내부 서버 오류를 제공하는 기본 python 스크립트

#!/usr/bin/python 
print "Content-type: text/html\n\n"; 
print "<html><head>"; 
print "<title>CGI Test</title>"; 
print "</head><body>"; 
print "<p>Test page using Python</p>"; 
print "</body></html>"; 

내가 내부 서버 오류 받고 있어요 : 이 http://elkuzu.com/cgi-bin/test.py

파일이 755 권한을 가진, 그래서 수행을 나는 여러 스크립트를 시도했습니다, 내 최신 하나는 자신의 웹 사이트에 줄 하나입니다 폴더 cgi-bin. 그들은 "코딩"문제라고 부르는 것을 도우려고 거부했지만 ... 내부 서버 오류 만 시도하고받은 모든 것으로, 문제가 있다고 생각합니다. 누구든지 무엇이 잘못 될 수 있는지 알고 있습니까?

오류 로그 :

[Sat May 19 09:11:38 2012] [error] [client 74.129.48.242] File does not exist: /home/elkuzu/public_html/404.shtml 
[Sat May 19 09:11:38 2012] [error] [client 74.129.48.242] File does not exist: /home/elkuzu/public_html/favicon.ico 
[Sat May 19 09:11:37 2012] [error] [client 74.129.48.242] File does not exist: /home/elkuzu/public_html/500.shtml 

내 호스트 (Hostgator에)와 함께 얘기했습니다 그들은 나에게 무언가가 자신의 말에 위로이라고 생각하게 티켓,로를 설정했습니다.

+0

로그는 무엇을 말하고 있습니까? –

+0

로그를 찾을 수없는 것 같습니다. 어디에서 볼 수 있습니까? cpanel? – Samir

+0

예, cpanel은 Apache 오류 로그를 찾습니다. –

답변

7

파이썬을 CGI로 사용하는 방법에는 documentation이 있습니다.

귀하의 경우 문제는 줄 끝입니다. 그들은 각 줄의 끝에 숨겨진 성격입니다. 유닉스에 그들이 (LF 또는 \n)입니다 반면

On a Unix-like system, The line endings in the program file must be Unix style line endings. This is important because the web server checks the first line of the script (called shebang) and tries to run the program specified there. It gets easily confused by Windows line endings (Carriage Return & Line Feed, also called CRLF), so you have to convert the file to Unix line endings (only Line Feed, LF). This can be done automatically by uploading the file via FTP in text mode instead of binary mode, but the preferred way is just telling your editor to save the files with Unix line endings. Most editors support this.

는 윈도우 (예 : 메모장)에 그들은 (CR LF 또는 \r\n)로 표현하고 있습니다.

Notepad++에서, 당신이 그렇게 같은 상징으로 라인 엔딩을 볼 수 있습니다 -> 표시 기호 -보기> 라인

의 표시 끝 유닉스 사람과 윈도우 바꿈를 교체하려면, 당신은 사용할 수 있습니다 검색 -> 바꾸기 ..

바꾸기 대화 상자에서 \r\n을 찾아 \n으로 바꿉니다. 확장 검색 모드가 선택되어 있는지 확인하십시오. > EOL 변환 - -

Notepad++ replace dialogue screenshot

또는

, 당신은 편집 사용할 수 있습니다> UNIX 형식을

Notepad++ EOL Conversion screenshot

+0

.htaccess를 시도했는데 루트 폴더에서 .py를 실행할 수있는 것처럼 보였지만 내부 서버 오류가 계속 나타났습니다. test.py 스크립트 하단에 추가 입력을 시도했지만 아무 것도 변경되지 않았습니다. – Samir

+0

@ 타일러 저는 제 답변을 업데이트했습니다 - 그 스크립트를 사용해 볼 수 있습니까? 파이썬 버전을 알려줄 것입니다. 어떤 세미콜론도 필요하지 않습니다. –

+0

동일한 내부 서버 오류 및 오류 로그의 동일한 오류 : http://elkuzu.com/cgi-bin/python3.py – Samir

0

나는이 오래된 질문 알아요,하지만 난 500 오류로 실행중인 hostgator와 함께 (1 년 전에 내가 그만 뒀다는 것을 지적하기 위해). 며칠 전 다시 "tutorial"다음에 다시 시도하기로 결정했으며 다시 작동하지 않았습니다.

[error] [client 192.x.x.x] malformed header from script. Bad header=(2, 6, 6, 'final', 0): test1.py

정보 (포함 된 로그 메시지와 함께 : 나는 500 오류가 발생했습니다

#!/usr/bin/python 
import sys 
print sys.version_info 

다시, 그러나 지원과 채팅을 한 후 그들이 말하는 로그 메시지 을했다 :

나는 간단하게 뭔가 시도 그래서 어떤 식 으로든 파이썬이 실행 중입니다.) Unix site에이 게시물을 발견했습니다. 여기에 내가 이것을 가지고 있습니다 :

As the HTTP spec (and the error message from your HTTP server) specify, you need one blank line between the HTTP headers and the body, otherwise the server doesn't know where the headers end and the body begins.

나는 내 스크립트를 변경 :

#!/usr/bin/python 
print "" 
import sys 
print sys.version_info 

그리고 그것은했다! 지금 작동 왜 이상하게도, 튜토리얼 (아래 코드)에 성공적으로 예를 들어이 스크립트를 실행 한 후 지금뿐만 아니라 나를 위해

#!/usr/bin/python 
print "Content-type: text/html\n\n"; 
print "<html><head>"; 
print "<title>CGI Test</title>"; 
print "</head><body>"; 
print "<p>Test page using Python</p>"; 
print "</body></html>"; 

을하고있다? 나는 단서가 없지만 적어도이 답변이 누군가가 hostgator [지원 부족]을 다루는 데 도움이되기를 바랍니다.

관련 문제