###前提・実現したいこと
python3.5.1 を用いて、みんなのpython webアプリ編を学習しています。
("webアプリケーションに値を渡す"に該当。)
以下の動作をするスクリプトを作りたいです。
・UIで現在の西暦の前後10年をoptionに与える。
・選ばれたoptionの西暦に13日の金曜日が何回あるかを返す。
自分なりにいろいろと試してみましたが解決できませんでした。
ご教授の程よろしくお願い致します。
###発生している問題・エラーメッセージ
line 44, in <module>\r\n print (html_body % (options, content))\r\nUnicodeEncodeError: \'cp932\' codec can\'t encode character \'\\ufffc\' in position 2: illegal multibyte sequence\r\n'
line44 は該当ソースコードの最後の行です。
###該当のソースコード
python
1# coding: utf-8 2 3import cgi 4from datetime import datetime 5html_body = """ 6<html><head> 7 <meta http-equiv="content-type" content="text/html" /> </head> 8<body> 9 <form method="POST" action="/cgi-bin/f13form.py"> 10西暦を選んでください:<select name="year"> 11 %s 12 </select> 13 <input type="submit" /> 14 </form> 15%s </body> 16</html>""" 17options='' 18content='' 19now=datetime.now() 20for y in range(now.year-10, now.year+10): 21 if y!=now.year: 22 select='' 23 else: 24 select= "selected" 25 options+="<option%s>%d</option>" % (select, y) 26form=cgi.FieldStorage() 27year_str=form.getvalue('year', '') 28if not year_str.isdigit(): 29 content = "西暦を入力してください" 30else: 31 year=int(year_str) 32 friday13=0 33 for month in range(1, 13): 34 date=datetime(year, month, 13) 35 if date.weekday()==4: 36 friday13+=1 37 content+="%d年%d月13日は金曜日です" % ( year, date.month) 38 content+="<br />" 39 if friday13: 40 content+="%d年には合計%d個の13日の金曜日があります" % ( year, friday13) 41 else: 42 content+="%d年には13日の金曜日がありません" 43print ("Content-type: text/html\n") 44print (html_body % (options, content)) 45
###補足情報(言語/FW/ツール等のバージョンなど)
windows10
python3.5.1
atom
を使っています。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2016/07/13 04:45
2016/07/13 05:15
2016/07/13 05:57
2016/07/13 06:05
2016/07/13 06:07
2016/07/13 06:08
2016/07/13 06:13
2016/07/13 06:25
2016/07/13 13:08