質問編集履歴
4
修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -368,9 +368,9 @@
|
|
368
368
|
|
369
369
|
```
|
370
370
|
|
371
|
-
root@
|
371
|
+
root@80094834d94e:/media/docker_shared/mono_develop/processing/src/python_cgi_src/cgi_bin# python run_detection.py 5000
|
372
|
-
|
372
|
+
|
373
|
-
1
|
373
|
+
153.240.33.132 - - [21/Jan/2021 15:17:27] "GET /ok-api HTTP/1.1" 200 -
|
374
374
|
|
375
375
|
Face: [175 x 175 from (216, 202)]
|
376
376
|
|
@@ -378,7 +378,7 @@
|
|
378
378
|
|
379
379
|
----------------------------------------
|
380
380
|
|
381
|
-
Exception happened during processing of request from ('1
|
381
|
+
Exception happened during processing of request from ('153.240.33.132', 1563)
|
382
382
|
|
383
383
|
Traceback (most recent call last):
|
384
384
|
|
@@ -394,11 +394,11 @@
|
|
394
394
|
|
395
395
|
self.RequestHandlerClass(request, client_address, self)
|
396
396
|
|
397
|
-
File "/media/docker_shared/mono_develop/processing/src/python_cgi_src/cgi_bin/python_http
|
397
|
+
File "/media/docker_shared/mono_develop/processing/src/python_cgi_src/cgi_bin/python_http.py", line 12, in handler
|
398
398
|
|
399
399
|
MyHTTPRequestHandler(callback, *args)
|
400
400
|
|
401
|
-
File "/media/docker_shared/mono_develop/processing/src/python_cgi_src/cgi_bin/python_http
|
401
|
+
File "/media/docker_shared/mono_develop/processing/src/python_cgi_src/cgi_bin/python_http.py", line 21, in __init__
|
402
402
|
|
403
403
|
BaseHTTPRequestHandler.__init__(self, *args)
|
404
404
|
|
@@ -414,7 +414,7 @@
|
|
414
414
|
|
415
415
|
method()
|
416
416
|
|
417
|
-
File "/media/docker_shared/mono_develop/processing/src/python_cgi_src/cgi_bin/python_http
|
417
|
+
File "/media/docker_shared/mono_develop/processing/src/python_cgi_src/cgi_bin/python_http.py", line 31, in do_GET
|
418
418
|
|
419
419
|
self.wfile.write("OK")
|
420
420
|
|
@@ -424,6 +424,12 @@
|
|
424
424
|
|
425
425
|
TypeError: a bytes-like object is required, not 'str'
|
426
426
|
|
427
|
+
----------------------------------------
|
428
|
+
|
429
|
+
153.240.33.132 - - [21/Jan/2021 15:17:28] code 400, message NG!
|
430
|
+
|
431
|
+
153.240.33.132 - - [21/Jan/2021 15:17:28] "GET /favicon.ico HTTP/1.1" 400 -
|
432
|
+
|
427
433
|
```
|
428
434
|
|
429
435
|
|
3
追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -426,4 +426,14 @@
|
|
426
426
|
|
427
427
|
```
|
428
428
|
|
429
|
+
|
430
|
+
|
429
431
|
TypeError: a bytes-like object is required, not 'str'とエラーがでます。
|
432
|
+
|
433
|
+
どこでエラーが出ているのかがわかりません。
|
434
|
+
|
435
|
+
|
436
|
+
|
437
|
+
また、
|
438
|
+
|
439
|
+
AWSのDockerコンテナ間でのHTTP通信の場合は、http://awsのip:5000/ok-apiにgetリクエストをかければ動作するという認識であっていますか?
|
2
追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -137,3 +137,293 @@
|
|
137
137
|
また、http://localhost:5000/ok-apiにアクセスすると、サーバが動いていないみたいなのですが、なぜなのでしょうか?
|
138
138
|
|
139
139
|
何を確認すればいいか分からないので教えてください。
|
140
|
+
|
141
|
+
|
142
|
+
|
143
|
+
### 追記
|
144
|
+
|
145
|
+
|
146
|
+
|
147
|
+
違うサイトから、書き方を変更してみました。
|
148
|
+
|
149
|
+
python_http_server.py
|
150
|
+
|
151
|
+
```
|
152
|
+
|
153
|
+
# coding: utf-8
|
154
|
+
|
155
|
+
from http.server import BaseHTTPRequestHandler, HTTPServer,\
|
156
|
+
|
157
|
+
SimpleHTTPRequestHandler
|
158
|
+
|
159
|
+
from urllib.parse import parse_qs, urlparse
|
160
|
+
|
161
|
+
|
162
|
+
|
163
|
+
def start(port, callback):
|
164
|
+
|
165
|
+
def handler(*args):
|
166
|
+
|
167
|
+
MyHTTPRequestHandler(callback, *args)
|
168
|
+
|
169
|
+
server = HTTPServer(('', int(port)), handler)
|
170
|
+
|
171
|
+
server.serve_forever()
|
172
|
+
|
173
|
+
|
174
|
+
|
175
|
+
|
176
|
+
|
177
|
+
# ハンドラを定義していく
|
178
|
+
|
179
|
+
class MyHTTPRequestHandler(BaseHTTPRequestHandler):
|
180
|
+
|
181
|
+
def __init__(self, callback, *args):
|
182
|
+
|
183
|
+
self.callback = callback
|
184
|
+
|
185
|
+
BaseHTTPRequestHandler.__init__(self, *args)
|
186
|
+
|
187
|
+
|
188
|
+
|
189
|
+
def do_GET(self):
|
190
|
+
|
191
|
+
parsed_path = urlparse.urlparse(self.path)
|
192
|
+
|
193
|
+
|
194
|
+
|
195
|
+
# 成功レスポンス(200)を返す
|
196
|
+
|
197
|
+
if parsed_path.path == "/ok-api":
|
198
|
+
|
199
|
+
self.send_response(200)
|
200
|
+
|
201
|
+
self.end_headers()
|
202
|
+
|
203
|
+
self.callback()
|
204
|
+
|
205
|
+
self.wfile.write("OK")
|
206
|
+
|
207
|
+
return
|
208
|
+
|
209
|
+
|
210
|
+
|
211
|
+
# 失敗レスポンス(403)を返す
|
212
|
+
|
213
|
+
elif parsed_path.path == "/ng-api":
|
214
|
+
|
215
|
+
self.send_error(403, "NG!")
|
216
|
+
|
217
|
+
self.end_headers()
|
218
|
+
|
219
|
+
return
|
220
|
+
|
221
|
+
|
222
|
+
|
223
|
+
# クエリパラメータ("left-str", "right-str")を連結した文字列を返す
|
224
|
+
|
225
|
+
# /concat-str?left-str=Hello&right-str=World
|
226
|
+
|
227
|
+
elif parsed_path.path == "/concat-str":
|
228
|
+
|
229
|
+
# クエリパラメータのパース(dictionary型)
|
230
|
+
|
231
|
+
querys = urlparse.parse_qs(parsed_path.query)
|
232
|
+
|
233
|
+
if ("left-str" in querys) and ("right-str" in querys):
|
234
|
+
|
235
|
+
concat_str = querys["left-str"][0] + querys["right-str"][0]
|
236
|
+
|
237
|
+
self.send_response(200)
|
238
|
+
|
239
|
+
self.end_headers()
|
240
|
+
|
241
|
+
self.wfile.write(concat_str)
|
242
|
+
|
243
|
+
|
244
|
+
|
245
|
+
else:
|
246
|
+
|
247
|
+
#"left-str"と"right-str"のクエリがなかったらエラー
|
248
|
+
|
249
|
+
self.send_error(400, "query NG!")
|
250
|
+
|
251
|
+
self.end_headers()
|
252
|
+
|
253
|
+
return
|
254
|
+
|
255
|
+
|
256
|
+
|
257
|
+
# Jsonを返す
|
258
|
+
|
259
|
+
elif parsed_path.path == "/return-json":
|
260
|
+
|
261
|
+
data = [{u"name":u"尾崎豊", u"age":26},
|
262
|
+
|
263
|
+
{u"name":u"hide", u"age":33}]
|
264
|
+
|
265
|
+
jsonData = json.dumps(data, ensure_ascii=False, encoding='utf-8')
|
266
|
+
|
267
|
+
|
268
|
+
|
269
|
+
self.send_response(200)
|
270
|
+
|
271
|
+
self.send_header("Content-type", "application/json")
|
272
|
+
|
273
|
+
self.end_headers()
|
274
|
+
|
275
|
+
|
276
|
+
|
277
|
+
self.wfile.write(jsonData.encode("utf-8"))
|
278
|
+
|
279
|
+
return
|
280
|
+
|
281
|
+
|
282
|
+
|
283
|
+
else:
|
284
|
+
|
285
|
+
self.send_error(400, "NG!")
|
286
|
+
|
287
|
+
self.end_headers()
|
288
|
+
|
289
|
+
return
|
290
|
+
|
291
|
+
```
|
292
|
+
|
293
|
+
|
294
|
+
|
295
|
+
run_detection.py
|
296
|
+
|
297
|
+
```
|
298
|
+
|
299
|
+
import sys
|
300
|
+
|
301
|
+
sys.path.append('site-packagesのパス')
|
302
|
+
|
303
|
+
from skimage import data, io, filters, color, img_as_ubyte
|
304
|
+
|
305
|
+
from sklearn import preprocessing
|
306
|
+
|
307
|
+
import numpy as np
|
308
|
+
|
309
|
+
import matplotlib.pyplot as plt
|
310
|
+
|
311
|
+
import scipy
|
312
|
+
|
313
|
+
import Cython
|
314
|
+
|
315
|
+
|
316
|
+
|
317
|
+
# C++で作成した共有ファイルの.soをインポート
|
318
|
+
|
319
|
+
import face_detection
|
320
|
+
|
321
|
+
# httpserver
|
322
|
+
|
323
|
+
import sys
|
324
|
+
|
325
|
+
import python_http
|
326
|
+
|
327
|
+
|
328
|
+
|
329
|
+
input_path = '/media/docker_shared/mono_develop/img/getImg.jpg'
|
330
|
+
|
331
|
+
output_path = '/media/docker_shared/mono_develop/img/kansei.jpg'
|
332
|
+
|
333
|
+
|
334
|
+
|
335
|
+
def call_processing():
|
336
|
+
|
337
|
+
try :
|
338
|
+
|
339
|
+
|
340
|
+
|
341
|
+
result_c_img = face_detection.face_detect()
|
342
|
+
|
343
|
+
|
344
|
+
|
345
|
+
except:
|
346
|
+
|
347
|
+
print('Error')
|
348
|
+
|
349
|
+
|
350
|
+
|
351
|
+
else:
|
352
|
+
|
353
|
+
print("finish (no error)")
|
354
|
+
|
355
|
+
|
356
|
+
|
357
|
+
if __name__ == '__main__':
|
358
|
+
|
359
|
+
port = sys.argv[1]
|
360
|
+
|
361
|
+
pythoon_http.start(port, call_processing)
|
362
|
+
|
363
|
+
|
364
|
+
|
365
|
+
```
|
366
|
+
|
367
|
+
|
368
|
+
|
369
|
+
```
|
370
|
+
|
371
|
+
root@f144c53506cb:/media/docker_shared/mono_develop/processing/src/python_cgi_src/cgi_bin# python run_detection_test.py 5000
|
372
|
+
|
373
|
+
172.19.0.1 - - [21/Jan/2021 13:49:59] "GET /ok-api HTTP/1.1" 200 -
|
374
|
+
|
375
|
+
Face: [175 x 175 from (216, 202)]
|
376
|
+
|
377
|
+
finish (no error)
|
378
|
+
|
379
|
+
----------------------------------------
|
380
|
+
|
381
|
+
Exception happened during processing of request from ('172.19.0.1', 63810)
|
382
|
+
|
383
|
+
Traceback (most recent call last):
|
384
|
+
|
385
|
+
File "/usr/lib/python3.6/socketserver.py", line 320, in _handle_request_noblock
|
386
|
+
|
387
|
+
self.process_request(request, client_address)
|
388
|
+
|
389
|
+
File "/usr/lib/python3.6/socketserver.py", line 351, in process_request
|
390
|
+
|
391
|
+
self.finish_request(request, client_address)
|
392
|
+
|
393
|
+
File "/usr/lib/python3.6/socketserver.py", line 364, in finish_request
|
394
|
+
|
395
|
+
self.RequestHandlerClass(request, client_address, self)
|
396
|
+
|
397
|
+
File "/media/docker_shared/mono_develop/processing/src/python_cgi_src/cgi_bin/python_http_test.py", line 13, in handler
|
398
|
+
|
399
|
+
MyHTTPRequestHandler(callback, *args)
|
400
|
+
|
401
|
+
File "/media/docker_shared/mono_develop/processing/src/python_cgi_src/cgi_bin/python_http_test.py", line 23, in __init__
|
402
|
+
|
403
|
+
BaseHTTPRequestHandler.__init__(self, *args)
|
404
|
+
|
405
|
+
File "/usr/lib/python3.6/socketserver.py", line 724, in __init__
|
406
|
+
|
407
|
+
self.handle()
|
408
|
+
|
409
|
+
File "/usr/lib/python3.6/http/server.py", line 418, in handle
|
410
|
+
|
411
|
+
self.handle_one_request()
|
412
|
+
|
413
|
+
File "/usr/lib/python3.6/http/server.py", line 406, in handle_one_request
|
414
|
+
|
415
|
+
method()
|
416
|
+
|
417
|
+
File "/media/docker_shared/mono_develop/processing/src/python_cgi_src/cgi_bin/python_http_test.py", line 34, in do_GET
|
418
|
+
|
419
|
+
self.wfile.write("OK")
|
420
|
+
|
421
|
+
File "/usr/lib/python3.6/socketserver.py", line 803, in write
|
422
|
+
|
423
|
+
self._sock.sendall(b)
|
424
|
+
|
425
|
+
TypeError: a bytes-like object is required, not 'str'
|
426
|
+
|
427
|
+
```
|
428
|
+
|
429
|
+
TypeError: a bytes-like object is required, not 'str'とエラーがでます。
|
1
追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -28,23 +28,9 @@
|
|
28
28
|
|
29
29
|
```
|
30
30
|
|
31
|
-
http://localhost:5000/ok-apiにアクセスしてみると
|
31
|
+
http://localhost:5000/ok-apiにアクセスしてみるとサーバが動作していないみたいです。
|
32
|
-
|
33
|
-
```
|
34
|
-
|
35
|
-
Error response
|
36
|
-
|
37
|
-
Error code: 404
|
38
32
|
|
39
33
|
|
40
|
-
|
41
|
-
Message: File not found.
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
Error code explanation: HTTPStatus.NOT_FOUND - Nothing matches the given URI.
|
46
|
-
|
47
|
-
```
|
48
34
|
|
49
35
|
|
50
36
|
|
@@ -147,3 +133,7 @@
|
|
147
133
|
```
|
148
134
|
|
149
135
|
スクリプトが実行された場合、サーバが受付モードになり、http://localhost:5000/ok-apiにアクセスがあった場合に該当の do_GETが動くと思ったのですが、実際にはスクリプトを実行すると、do_GETが実行されてしまいます。
|
136
|
+
|
137
|
+
また、http://localhost:5000/ok-apiにアクセスすると、サーバが動いていないみたいなのですが、なぜなのでしょうか?
|
138
|
+
|
139
|
+
何を確認すればいいか分からないので教えてください。
|