エラーが出てしまいます。
文字コード
sjis
python
1# -*- coding: utf-8 -*- 2 3from flask import * 4import os 5import json 6import re 7import sys 8 9 10 11 12app = Flask(__name__) 13app.secret_key = '佐久間さん可愛い' 14 15#画像の準備 16image_ptrn = re.compile('.*[.](jpg|jpeg|png)|') 17image_dir = os.path.join( 'TrainingAssistant','static', 'img' ) 18images = [] 19images = [ image for image in os.listdir( image_dir ) if re.match( image_ptrn, image ) ] 20if not len( images ): 21 sys.exit( 'Error: Could not find images') 22 23logf = open('log.dat', 'w') 24 25pos = 0 26 27@app.route('/') 28def index(): 29 30 global pos 31 32 #正例と負例用のファイル 33 global positive 34 global negative 35 36 positive = open('info.dat', 'a') 37 negative = open('bg.txt', 'a') 38 39 #最初の画像 40 imgsrc = os.path.join( image_dir, images[pos] ) 41 imgnum = len(images) 42 count = pos 43 counter = ''.join( [ str(pos+1).zfill( len(str(imgnum)) ), ' of ', str(imgnum) ] ) 44 45 return render_template( 'index.html', imgsrc=imgsrc, imgnum=imgnum, count=count, counter=counter ) 46 47@app.route('/_next') 48def _next(): 49 50 global pos 51 52 #その画像をスキップするか 53 skip = request.args.get('skip') 54 55 if skip == u'0': 56 57 #囲まれた範囲の座標 58 coords = request.args.get('coords') 59 coords = json.loads(coords) 60 61 #処理中の画像のパス 62 image_path = os.path.join( image_dir, images[pos] ) 63 64 #正例か負例か 65 if len(coords) == 0: 66 negative.write( ''.join( [ image_path, '\n' ] ) ) 67 logf.write( ''.join( [ image_path, '\n' ] ) ) 68 logf.flush() 69 70 else: 71 s = '' 72 for coord in coords: 73 s = ' '.join( [ s, ' '.join( [ str(int(e)) for e in coord ] ) ] ) 74 75 positive.write('%s %d%s\n' % (image_path, len(coords), s)) 76 logf.write( "%s %d%s\n" % (image_path, len(coords), s) ) 77 logf.flush() 78 79 #まだ画像があるか 80 if pos+1 >= len(images): 81 imgsrc = "" 82 finished = True 83 pos = pos + 1 84 logf.close() 85 negative.close() 86 positive.close() 87 else: 88 finished = False 89 imgsrc = os.path.join( image_dir, images[pos+1] ) 90 pos = pos + 1 91 92 return jsonify( imgsrc=imgsrc, finished=finished, count=pos ) 93 94if __name__ == '__main__': 95 app.debug = True 96 app.run() 97
エラーメッセージ
C:\Users\saito\Anaconda3\envs\in_anaconda\python.exe C:/Users/saito/PycharmProjects/in_anaconda/views.py
- Serving Flask app "views" (lazy loading)
- Environment: production
WARNING: Do not use the development server in a production environment.
Use a production WSGI server instead. - Debug mode: on
- Restarting with stat
- Debugger is active!
- Debugger PIN: 332-401-681
Exception in thread Thread-1:
Traceback (most recent call last):
File "C:\Users\saito\Anaconda3\envs\in_anaconda\lib\threading.py", line 916, in _bootstrap_inner
self.run()
File "C:\Users\saito\Anaconda3\envs\in_anaconda\lib\threading.py", line 864, in run
self._target(*self._args, **self._kwargs)
File "C:\Users\saito\Anaconda3\envs\in_anaconda\lib\site-packages\werkzeug\serving.py", line 774, in inner
fd=fd)
File "C:\Users\saito\Anaconda3\envs\in_anaconda\lib\site-packages\werkzeug\serving.py", line 660, in make_server
passthrough_errors, ssl_context, fd=fd)
File "C:\Users\saito\Anaconda3\envs\in_anaconda\lib\site-packages\werkzeug\serving.py", line 577, in init
self.address_family), handler)
File "C:\Users\saito\Anaconda3\envs\in_anaconda\lib\socketserver.py", line 453, in init
self.server_bind()
File "C:\Users\saito\Anaconda3\envs\in_anaconda\lib\http\server.py", line 138, in server_bind
self.server_name = socket.getfqdn(host)
File "C:\Users\saito\Anaconda3\envs\in_anaconda\lib\socket.py", line 673, in getfqdn
hostname, aliases, ipaddrs = gethostbyaddr(name)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x82 in position 0: invalid start byte
どのような処理をすれば実行できるかコメントお願いします!!
回答1件
あなたの回答
tips
プレビュー