質問編集履歴

1

data = r.json()の前の行に、r.raise_for_status()を追加しました。requests.post(url=url, json=json_data) に変更しました。

2018/07/18 11:47

投稿

denshi
denshi

スコア4

test CHANGED
File without changes
test CHANGED
@@ -14,27 +14,11 @@
14
14
 
15
15
  Traceback (most recent call last):
16
16
 
17
- File "/home/pi/ni.py", line 22, in <module>
17
+ File "/home/pi/ni.py", line 21, in <module>
18
18
 
19
- data = r.json()
19
+ r = requests.post(url=url, json=json_data)
20
20
 
21
- File "/home/pi/.local/lib/python2.7/site-packages/requests/models.py", line 896, in json
22
-
23
- return complexjson.loads(self.text, **kwargs)
24
-
25
- File "/usr/lib/python2.7/dist-packages/simplejson/__init__.py", line 516, in loads
26
-
27
- return _default_decoder.decode(s)
28
-
29
- File "/usr/lib/python2.7/dist-packages/simplejson/decoder.py", line 374, in decode
30
-
31
- obj, end = self.raw_decode(s)
32
-
33
- File "/usr/lib/python2.7/dist-packages/simplejson/decoder.py", line 404, in raw_decode
34
-
35
- return self.scan_once(s, idx=_w(s, idx).end())
36
-
37
- JSONDecodeError: Expecting value: line 1 column 1 (char 0)
21
+ NameError: name 'json_data' is not defined
38
22
 
39
23
 
40
24
 
@@ -90,7 +74,9 @@
90
74
 
91
75
  #送信
92
76
 
93
- r = requests.post(url, data=json.dumps(payload), headers=headers)
77
+ r = requests.post(url=url, json=json_data)
78
+
79
+ r.raise_for_status()
94
80
 
95
81
  data = r.json()
96
82
 
@@ -136,10 +122,6 @@
136
122
 
137
123
  print "response: %s" %(response)
138
124
 
139
- ```
140
-
141
-
142
-
143
125
 
144
126
 
145
127
  ### 補足情報(FW/ツールのバージョンなど)