前提・実現したいこと
windows10にpython2.7 32bitでcgiを使ってサーバーを建てようとしています.
発生している問題・エラーメッセージ
google cromeでアクセスするとこのように表示されます.
webエラーメッセージ
1Error response 2Error code 404. 3 4Message: File not found. 5 6Error code explanation: 404 = Nothing matches the given URI.
該当のソースコードが.pyファイルでpyファイルを実行すると
Content-Type:text/plain Traceback (most recent call last): File "oneday.py", line 33, in <module> if os.environ['REQUEST_METHOD'] != 'POST': File "C:\Python27\lib\os.py", line 425, in __getitem__ return self.data[key.upper()] KeyError: 'REQUEST_METHOD'
というエラーになります.
該当のソースコード
python2.7
1#! C:\Python27_x86\python 2# coding:utf-8 3 4import cgi 5import os, sys 6import ConfigParser 7 8try: 9 import msvcrt 10 msvcrt.setmode(0, os.O_BINARY) 11 msvcrt.setmode(1, os.O_BINARY) 12except ImportError: 13 pass 14 15inifile = ConfigParser.SafeConfigParser() 16inifile.read("./config.ini") 17user_name = inifile.get("settings","user") 18 19top_dir = r"C:\Users***\Desktop\oneday" 20upload_dir = top_dir + "\" +user_name + r"\interaction\orig" 21output_dir = top_dir + "\" + user_name + r"\interaction\face" 22file_path = r"" 23log_path = top_dir+ "\" + user_name + r"\interaction" 24processing_flag = False 25facial_class = ["Neutral","Anger","Happiness"] 26 27dic_pic_flag = False#辞書用画像かどうかの判断 28 29#コンテンツのMIMEを指定 30#print('Content-Type:text/plain\n') 31print 'Content-Type:text/plain\n' 32 33if os.environ['REQUEST_METHOD'] != 'POST': 34 print '不正なアクセスです。POSTでアクセスしてください' 35 36else: 37 htmltext = "" 38 39 form = cgi.FieldStorage() 40 41 if form.has_key("image"): 42 fileitem = form["image"] 43 if(fileitem.file): 44 file_path =os.path.join(upload_dir,os.path.basename(fileitem.filename)) 45 fout = file (file_path, 'wb') 46 while 1: 47 chunk = fileitem.file.read(100000) 48 if not chunk: break 49 fout.write (chunk) 50 fout.close() 51 processing_flag = True 52 53 else: 54 htmltext = '-10' # not found file 55 else: 56 htmltext = '-20' # not found key 57 58 59 for fclass_label in facial_class:#辞書用画像かチェック 60 if fclass_label in fileitem.filename: 61 dic_pic_flag = True 62 break 63 64 if processing_flag: 65 import kiridashi 66 out_path =os.path.join(output_dir,os.path.basename(fileitem.filename)) 67 kiridashi.processing_kiridashi(file_path,out_path) 68 69 if(not dic_pic_flag):#辞書画像作成時は類似度計算しない 70 import Calc_on_EMC 71 sim_and_fclass = Calc_on_EMC.Calc(file_path) 72 73 with open(log_path+r"\result.txt","a") as f: 74 if sim_and_fclass.result >= 0:#顔検出された 75 f.write(fileitem.filename + " / class is " + facial_class[sim_and_fclass.result] + "\n") 76 htmltext = str(sim_and_fclass.result) 77 78 with open(log_path+r"\sim.csv","a") as sim_file: #類似度書き出し 79 sim_file.write(fileitem.filename) 80 for sim_array in sim_and_fclass.sim: 81 for sim_value in sim_array: 82 sim_file.write(","+str(sim_value)) 83 htmltext += ","+str(sim_value) 84 sim_file.write("\n") 85 else:#顔が検出されなかった 86 f.write(fileitem.filename + " / No detect \n") 87 htmltext = str(sim_and_fclass.result)+",0,0,0" 88 89 print htmltext
試したこと
apacheでの実行も試しましたがいきませんでした
補足情報(FW/ツールのバージョンなど)
ここにより詳細な情報を記載してください。
できることを一歩ずつやっていくようにしてください。
いきなり100歩先の結果を望むのであれば、お金を払って他人にやってもらうしかないです。
回答2件
あなたの回答
tips
プレビュー