質問するログイン新規登録

質問編集履歴

1

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

2018/07/18 11:47

投稿

denshi
denshi

スコア4

title CHANGED
File without changes
body CHANGED
@@ -6,17 +6,9 @@
6
6
 
7
7
  ```
8
8
  Traceback (most recent call last):
9
- File "/home/pi/ni.py", line 22, in <module>
9
+ File "/home/pi/ni.py", line 21, in <module>
10
- data = r.json()
11
- File "/home/pi/.local/lib/python2.7/site-packages/requests/models.py", line 896, in json
12
- return complexjson.loads(self.text, **kwargs)
13
- File "/usr/lib/python2.7/dist-packages/simplejson/__init__.py", line 516, in loads
14
- return _default_decoder.decode(s)
15
- File "/usr/lib/python2.7/dist-packages/simplejson/decoder.py", line 374, in decode
16
- obj, end = self.raw_decode(s)
17
- File "/usr/lib/python2.7/dist-packages/simplejson/decoder.py", line 404, in raw_decode
18
- return self.scan_once(s, idx=_w(s, idx).end())
10
+ r = requests.post(url=url, json=json_data)
19
- JSONDecodeError: Expecting value: line 1 column 1 (char 0)
11
+ NameError: name 'json_data' is not defined
20
12
 
21
13
  ```
22
14
 
@@ -44,7 +36,8 @@
44
36
  headers = {'Content-type': 'application/json'}
45
37
 
46
38
  #送信
47
- r = requests.post(url, data=json.dumps(payload), headers=headers)
39
+ r = requests.post(url=url, json=json_data)
40
+ r.raise_for_status()
48
41
  data = r.json()
49
42
 
50
43
  #jsonの解析
@@ -67,9 +60,7 @@
67
60
  context = data['context']
68
61
 
69
62
  print "response: %s" %(response)
70
- ```
71
63
 
72
-
73
64
  ### 補足情報(FW/ツールのバージョンなど)
74
65
 
75
66
  ラズベリーパイ3でやっています。