質問編集履歴

1

ソースコードの編集

2018/05/18 00:26

投稿

ths
ths

スコア21

test CHANGED
File without changes
test CHANGED
@@ -6,17 +6,37 @@
6
6
 
7
7
 
8
8
 
9
+ 【コードを書き直したのですが、新たなエラーが出ました。】
10
+
9
11
  ```ここに言語を入力
10
-
11
- {'error': {'code': '105', 'message': 'Request body is invalid format.'}}
12
12
 
13
13
  Traceback (most recent call last):
14
14
 
15
- File "image_recognition.py", line 48, in <module>
15
+ File "image_recognition.py", line 46, in <module>
16
16
 
17
- for can in candidate_list:
17
+ candidate_list = getImageCategory(fname, model_name)
18
18
 
19
- TypeError: 'NoneType' object is not iterable
19
+ File "image_recognition.py", line 29, in getImageCategory
20
+
21
+ data = result.json()
22
+
23
+ File "C:\Users\user\AppData\Local\Continuum\anaconda3\envs\opencv\lib\site-packages\requests\models.py", line 850, in json
24
+
25
+ return complexjson.loads(self.text, **kwargs)
26
+
27
+ File "C:\Users\user\AppData\Local\Continuum\anaconda3\envs\opencv\lib\json\__init__.py", line 354, in loads
28
+
29
+ return _default_decoder.decode(s)
30
+
31
+ File "C:\Users\user\AppData\Local\Continuum\anaconda3\envs\opencv\lib\json\decoder.py", line 339, in decode
32
+
33
+ obj, end = self.raw_decode(s, idx=_w(s, 0).end())
34
+
35
+ File "C:\Users\user\AppData\Local\Continuum\anaconda3\envs\opencv\lib\json\decoder.py", line 357, in raw_decode
36
+
37
+ raise JSONDecodeError("Expecting value", s, err.value) from None
38
+
39
+ json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
20
40
 
21
41
  ```
22
42
 
@@ -34,13 +54,11 @@
34
54
 
35
55
  url = 'https://api.apigw.smt.docomo.ne.jp/imageRecognition/v1/concept/classify/'
36
56
 
37
- params = {'APIKEY': APIKEY, 'recog': 'product-all', 'numOfCandidates': 1}
57
+ params = {'APIKEY': APIKEY, 'image': img, 'modelName': modelName}
38
-
39
- f = open(fname, 'rb')
40
58
 
41
59
 
42
60
 
43
- headers = {'Content-Type': 'application/octet-stream'}
61
+ headers = {'Content-Type': 'multipart/form-data'}
44
62
 
45
63
 
46
64
 
@@ -49,8 +67,6 @@
49
67
  url = url,
50
68
 
51
69
  params = params,
52
-
53
- data = f,
54
70
 
55
71
  headers = headers,
56
72