追記
現在はこのようなエラーがでます
IndentationError: unindent does not match any outer indentation level 127.0.0.1 - - [18/Nov/2017 02:52:47] CGI script exit status 0x100 127.0.0.1 - - [18/Nov/2017 02:52:52] "GET /cgi-bin/kakugen.py HTTP/1.1" 200 - File "/Users/en/cgi-bin/kakugen.py", line 66 elif mode == "write":mode_write(form)
↓下の問題は解決いたしました。
下記のようなエラーが出ます。
違う中身のコードを書いた時には、このファイル名を使っても、実行できます。
コードの内容に問題があるのでしょうか?アドバイスをいただけないでしょうか?
127.0.0.1 - - [18/Nov/2017 02:18:13] CGI script exit status 0x7f00 127.0.0.1 - - [18/Nov/2017 02:19:08] "GET /cgi-bin/kakugen.py HTTP/1.1" 200 - ---------------------------------------- Exception happened during processing of request from ('127.0.0.1', 51877) Traceback (most recent call last): File "/Users/en/anaconda/lib/python3.6/http/server.py", line 1126, in run_cgi os.execve(scriptfile, args, env) FileNotFoundError: [Errno 2] No such file or directory: '/Users/en/cgi-bin/kakugen.py' ---------------------------------------- 127.0.0.1 - - [18/Nov/2017 02:19:08] CGI script exit status 0x7f00
#!/usr/bin/env python3 import cgi import cgitb import os.path import html cgitb.enable() FILE_LOG="chat-log.txt" def print_html(body): print("Content-Type: text/html; cahrset=utf-8") print("") print(""" <html><head><meta charset="utf-8"> <title>チャット</title></head><body> <h1>チャット</h1> <div><form> 名前:<input type="text" name="name" size="8"> 本文:<input type="text name="body" size="20"> <input type="submit" value="発言"> <input type="hidden" name="mode" value="write"> </form></div><hr> {0} </body></html> """.format(body)) def mode_read(form): log="" if os.path.exists(FILE_LOG): with oepn(FILE_LOG,"r",encoding='utf-8')as f: log=f.read() print_html(log) def jump(url): print("Status:301 Moved Permanently") print("Location:"+url) print("") print('<html><head>') print('<meta http-equiv="refresh" content="0;'+url+'">') print('</head><body>') print('<a href="'+url+'">jump</a></body></html>') def mode_write(form): name=form.getvalue("name","no name") body=form.getvalue("body","") name=html.escape(name) body=html.escape(body) with open(FILE_LOG,"a+",encoding='utf-8') as f: f.write("<p>{0}: {1}</p><hr>\n".format(name,body)) jump('kakugen.py') def main(): form = cgi.FieldStrage() mode=form.getvalue("mode","read") if mode =="read": mode_read(form) elif mode == "write":mode_write(form) else:mode_read(form) if __name__ == "__main__": main()
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/11/17 17:45
2017/11/17 17:46
2017/11/17 17:52
2017/11/17 17:54
2017/11/17 17:54
2017/11/17 17:56
2017/11/17 18:19
2017/11/18 04:14
2017/11/18 04:15
2017/11/19 04:05