質問編集履歴

4

サーバのログ、POSTプログラムの更新

2017/07/02 14:26

投稿

kon_ta
kon_ta

スコア81

test CHANGED
File without changes
test CHANGED
@@ -164,14 +164,14 @@
164
164
 
165
165
  ```
166
166
 
167
- <プロキシサーバ上のログ>
167
+ <プロキシサーバ上のログ(POST)>
168
168
 
169
169
 
170
170
 
171
- 2017/07/01 17:36:52 [001] INFO: GOT request /index.php 172.20.69.88 POST http://172.20.69.88/index.php
171
+ 2017/07/02 23:18:03 [002] INFO: Got request /post/ httpbin.org POST http://httpbin.org/post/
172
172
 
173
- 2017/07/01 17:36:52 [001] INFO: Sending request POST https://172.20.69.88/index.php
173
+ 2017/07/02 23:18:03 [002] INFO: Sending request POST https://httpbin.org/post/
174
174
 
175
- 2017/07/01 17:36:52 [001] INFO: error read response 172.20.69.88 http: invalid Read on closed body
175
+ 2017/07/02 23:18:04 [002] INFO: error read response httpbin.org http: invalid Read on closed Body:
176
176
 
177
177
  ```

3

確認用POSTプログラムの追加

2017/07/02 14:26

投稿

kon_ta
kon_ta

スコア81

test CHANGED
File without changes
test CHANGED
@@ -126,6 +126,44 @@
126
126
 
127
127
  ```
128
128
 
129
+ <POSTプログラム>
130
+
131
+ import pprint
132
+
133
+ import json
134
+
135
+ import requests
136
+
137
+
138
+
139
+ def main()
140
+
141
+ response = requests.post(
142
+
143
+ http://httpbin.org/post',
144
+
145
+ json,dumps({'foo':'bar'}),
146
+
147
+ headers={'Content-Type': 'application/json'})
148
+
149
+ pprint.pprint(response.json())
150
+
151
+
152
+
153
+
154
+
155
+ if __name__=='__main__':
156
+
157
+ main()
158
+
159
+
160
+
161
+
162
+
163
+ ```
164
+
165
+ ```
166
+
129
167
  <プロキシサーバ上のログ>
130
168
 
131
169
 

2

エラー情報の追加

2017/07/02 12:13

投稿

kon_ta
kon_ta

スコア81

test CHANGED
File without changes
test CHANGED
@@ -81,3 +81,59 @@
81
81
  main()
82
82
 
83
83
  ```
84
+
85
+ ```
86
+
87
+ <クライアントサイドのターミナルのエラー>
88
+
89
+ user@user-desktop:~$ python sample.py
90
+
91
+ {"press": 1020, "hum": 39.1, "temp": 21.8, "datetime": "2017/07/01 17:36:52"}
92
+
93
+ Traceback (most recent call last):
94
+
95
+ File "sample.py", line 28, in <module>
96
+
97
+ main()
98
+
99
+ File "sample.py", line 25, in main
100
+
101
+ uploadSensorValues(21.8, 39.1, 1020)
102
+
103
+ File "sample.py", line 20, in uploadSensorValues
104
+
105
+ print res.json()
106
+
107
+ File "/usr/lib/python2.7/dist-packages/requests/models.py", line 808, in json
108
+
109
+ return complexjson.loads(self.text, **kwargs)
110
+
111
+ File "/usr/lib/python2.7/json/__init__.py", line 339, in loads
112
+
113
+ return _default_decoder.decode(s)
114
+
115
+ File "/usr/lib/python2.7/json/decoder.py", line 364, in decode
116
+
117
+ obj, end = self.raw_decode(s, idx=_w(s, 0).end())
118
+
119
+ File "/usr/lib/python2.7/json/decoder.py", line 382, in raw_decode
120
+
121
+ raise ValueError("No JSON object could be decoded")
122
+
123
+ ValueError: No JSON object could be decoded
124
+
125
+ ```
126
+
127
+ ```
128
+
129
+ <プロキシサーバ上のログ>
130
+
131
+
132
+
133
+ 2017/07/01 17:36:52 [001] INFO: GOT request /index.php 172.20.69.88 POST http://172.20.69.88/index.php
134
+
135
+ 2017/07/01 17:36:52 [001] INFO: Sending request POST https://172.20.69.88/index.php
136
+
137
+ 2017/07/01 17:36:52 [001] INFO: error read response 172.20.69.88 http: invalid Read on closed body
138
+
139
+ ```

1

ソースコード追加

2017/07/01 08:44

投稿

kon_ta
kon_ta

スコア81

test CHANGED
File without changes
test CHANGED
@@ -15,3 +15,69 @@
15
15
 
16
16
 
17
17
  どなたか知識のある方、回答の方宜しくお願い致します。
18
+
19
+
20
+
21
+
22
+
23
+ ###ソースコード(送信するjsonデータ)
24
+
25
+ ```ここに言語を入力
26
+
27
+ import requests
28
+
29
+ import json
30
+
31
+
32
+
33
+ from datetime import datetime
34
+
35
+
36
+
37
+ def uploadSensorValues(temp, hum, press):
38
+
39
+
40
+
41
+ url = 'http://172.20.69.88/index.php'
42
+
43
+
44
+
45
+ sensorsdata = {'datetime':datetime.now().strftime("%Y/%m/%d %H:%M:%S"),'temp':temp,'hum':hum,'press':press}
46
+
47
+
48
+
49
+ print json.dumps(sensorsdata)
50
+
51
+
52
+
53
+ headers = {'content-type': 'application/json'}
54
+
55
+ ps = {
56
+
57
+ "http": "http://172.20.69.177:8080",
58
+
59
+ }
60
+
61
+ res = requests.post(url, data=json.dumps(sensorsdata), headers=headers, verify=False,proxies = ps)
62
+
63
+
64
+
65
+ print res.json()
66
+
67
+ pass
68
+
69
+
70
+
71
+ def main():
72
+
73
+
74
+
75
+ uploadSensorValues(21.8, 39.1, 1020)
76
+
77
+
78
+
79
+ if __name__ == '__main__':
80
+
81
+ main()
82
+
83
+ ```