質問編集履歴

6

2018/05/28 04:40

投稿

退会済みユーザー
test CHANGED
@@ -1 +1 @@
1
- 例外の無視 タイムアウト HTTPSConnectionPool(host='api.zaif.jp', port=443): Read timed out. (read timeout=10)
1
+ 例外の無視 タイムアウト
test CHANGED
@@ -35,297 +35,3 @@
35
35
  https://code.i-harness.com/ja/q/b268c
36
36
 
37
37
  https://teratail.com/questions/109954
38
-
39
-
40
-
41
- ポイント:
42
-
43
-
44
-
45
- 例外(エラー)が発生しそうな処理「だけ」try: except:で囲う
46
-
47
-
48
-
49
-
50
-
51
- 対象pgm
52
-
53
-
54
-
55
- ```ここに言語を入力
56
-
57
- r = exchange[1].create_order(
58
-
59
- symbol=target_currency,
60
-
61
- type="limit",
62
-
63
- side="buy",
64
-
65
- amount= 100,
66
-
67
- price= 100
68
-
69
- ```
70
-
71
-
72
-
73
- ERROR
74
-
75
-
76
-
77
- ```ここに言語を入力
78
-
79
- 1つめ
80
-
81
- raise exception_type(output)
82
-
83
- ccxt.base.errors.RequestTimeout: zaif POST https://api.zaif.jp/tapi HTTPSConnectionPool(host='api.zaif.jp', port=443): Read timed out. (read timeout=10)
84
-
85
-
86
-
87
- 2つめ
88
-
89
- raise ReadTimeoutError(self, url, "Read timed out. (read timeout=%s)" % timeout_value)
90
-
91
- urllib3.exceptions.ReadTimeoutError: HTTPSConnectionPool(host='api.bitflyer.jp', port=443): Read timed out. (read timeout=10)
92
-
93
-
94
-
95
- ```
96
-
97
-
98
-
99
- 参考にしたtry 文
100
-
101
- ```ここに言語を入力
102
-
103
- from_datetime = '2017-01-01 00:00:00'
104
-
105
- from_timestamp = exchange.parse8601(from_datetime)
106
-
107
-
108
-
109
- # -----------------------------------------------------------------------------
110
-
111
-
112
-
113
- now = exchange.milliseconds()
114
-
115
-
116
-
117
- # -----------------------------------------------------------------------------
118
-
119
-
120
-
121
- data = []
122
-
123
-
124
-
125
- while from_timestamp < now:
126
-
127
-
128
-
129
- try:
130
-
131
-
132
-
133
- print(exchange.milliseconds(), 'Fetching candles starting from', exchange.iso8601(from_timestamp))
134
-
135
- ohlcvs = exchange.fetch_ohlcv('BTC/USD', '5m', from_timestamp)
136
-
137
- print(exchange.milliseconds(), 'Fetched', len(ohlcvs), 'candles')
138
-
139
- first = ohlcvs[0][0]
140
-
141
- last = ohlcvs[-1][0]
142
-
143
- print('First candle epoch', first, exchange.iso8601(first))
144
-
145
- print('Last candle epoch', last, exchange.iso8601(last))
146
-
147
- from_timestamp += len(ohlcvs) * minute * 5
148
-
149
- data += ohlcvs
150
-
151
-
152
-
153
- except (ccxt.ExchangeError, ccxt.AuthenticationError, ccxt.ExchangeNotAvailable, ccxt.RequestTimeout) as error:
154
-
155
-
156
-
157
- print('Got an error', type(error).__name__, error.args, ', retrying in', hold, 'seconds...')
158
-
159
- time.sleep(hold)
160
-
161
- ```
162
-
163
-
164
-
165
-
166
-
167
- RequestTimeoutについての説明
168
-
169
-
170
-
171
- This exception is raised when the connection with the exchange fails or data is not fully received in a specified amount of time. This is controlled by the timeout option. When a RequestTimeout is raised, the user doesn't know the outcome of a request (whether it was accepted by the exchange server or not).
172
-
173
-
174
-
175
- Thus it's advised to handle this type of exception in the following manner:
176
-
177
-
178
-
179
- for fetching requests it is safe to retry the call
180
-
181
- for a request to cancelOrder a user is required to retry the same call the second time. If instead of a retry a user calls a fetchOrder, fetchOrders, fetchOpenOrders or fetchClosedOrders right away without a retry to call cancelOrder, this may cause the .orders cache to fall out of sync. A subsequent retry to cancelOrder will return one of the following possible results:
182
-
183
- a request is completed successfully, meaning the order has been properly canceled now
184
-
185
- an OrderNotFound exception is raised, which means the order was either already canceled on the first attempt or has been executed (filled and closed) in the meantime between the two attempts. Note, that the order will still have an 'open' status in the .orders cache. To determine the actual order status you'll need to call fetchOrder to update the cache properly (where available from the exchange). If the fetchOrder method is 'emulated' the ccxt library will mark the order as 'closed'. The user has to call fetchBalance and set the order status to 'canceled' manually if the balance hasn't changed (a trade didn't not occur).
186
-
187
-
188
-
189
- **今回エラーが出ているcreateorderのtimeoutにおける2つの対応推奨案**
190
-
191
-
192
-
193
- if a request to createOrder fails with a RequestTimeout the user should:
194
-
195
- update the .orders cache with a call to fetchOrders, fetchOpenOrders, fetchClosedOrders to check if the request to place the order has succeeded and the order is now open
196
-
197
- if the order is not 'open' the user should fetchBalance to check if the balance has changed since the order was created on the first run and then was filled and closed by the time of the second check. Note that fetchBalance relies on the .orders cache for balance inference and thus should only be called after updating the cache!
198
-
199
-
200
-
201
-
202
-
203
- 同じソース箇所で出た2つ目のエラー
204
-
205
-
206
-
207
- ```ここに言語を入力
208
-
209
- raise ReadTimeoutError(self, url, "Read timed out. (read timeout=%s)" % timeout_value)
210
-
211
- urllib3.exceptions.ReadTimeoutError: HTTPSConnectionPool(host='api.bitflyer.jp', port=443): Read timed out. (read timeout=10)
212
-
213
- ```
214
-
215
-
216
-
217
- **エラー詳細**
218
-
219
-
220
-
221
- ```ここに言語を入力
222
-
223
- Traceback (most recent call last):
224
-
225
-
226
-
227
- socket.timeout: The read operation timed out
228
-
229
-
230
-
231
- During handling of the above exception, another exception occurred:
232
-
233
-
234
-
235
- Traceback (most recent call last):
236
-
237
- File "C:\Users\hogehoge\AppData\Local\Programs\Python\Python36\lib\site-packages\requests\adapters.py", line 440, in send
238
-
239
- timeout=timeout
240
-
241
- File "C:\Users\hogehoge\AppData\Local\Programs\Python\Python36\lib\site-packages\urllib3\connectionpool.py", line 639, in urlopen
242
-
243
- _stacktrace=sys.exc_info()[2])
244
-
245
- File "C:\Users\hogehoge\AppData\Local\Programs\Python\Python36\lib\site-packages\urllib3\util\retry.py", line 357, in increment
246
-
247
- raise six.reraise(type(error), error, _stacktrace)
248
-
249
- File "C:\Users\hogehoge\AppData\Local\Programs\Python\Python36\lib\site-packages\urllib3\packages\six.py", line 686, in reraise
250
-
251
- raise value
252
-
253
- File "C:\Users\hogehoge\AppData\Local\Programs\Python\Python36\lib\site-packages\urllib3\connectionpool.py", line 601, in urlopen
254
-
255
- chunked=chunked)
256
-
257
- File "C:\Users\hogehoge\AppData\Local\Programs\Python\Python36\lib\site-packages\urllib3\connectionpool.py", line 389, in _make_request
258
-
259
- self._raise_timeout(err=e, url=url, timeout_value=read_timeout)
260
-
261
- File "C:\Users\hogehoge\AppData\Local\Programs\Python\Python36\lib\site-packages\urllib3\connectionpool.py", line 309, in _raise_timeout
262
-
263
- raise ReadTimeoutError(self, url, "Read timed out. (read timeout=%s)" % timeout_value)
264
-
265
- urllib3.exceptions.ReadTimeoutError: HTTPSConnectionPool(host='api.bitflyer.jp', port=443): Read timed out. (read timeout=10)
266
-
267
-
268
-
269
- During handling of the above exception, another exception occurred:
270
-
271
-
272
-
273
- Traceback (most recent call last):
274
-
275
- File "C:\Users\hogehoge\AppData\Local\Programs\Python\Python36\lib\site-packages\ccxt\base\exchange.py", line 357, in fetch
276
-
277
- proxies=self.proxies
278
-
279
- File "C:\Users\hogehoge\AppData\Local\Programs\Python\Python36\lib\site-packages\requests\sessions.py", line 508, in request
280
-
281
- resp = self.send(prep, **send_kwargs)
282
-
283
- File "C:\Users\hogehoge\AppData\Local\Programs\Python\Python36\lib\site-packages\requests\sessions.py", line 618, in send
284
-
285
- r = adapter.send(request, **kwargs)
286
-
287
- File "C:\Users\hogehoge\AppData\Local\Programs\Python\Python36\lib\site-packages\requests\adapters.py", line 521, in send
288
-
289
- raise ReadTimeout(e, request=request)
290
-
291
- requests.exceptions.ReadTimeout: HTTPSConnectionPool(host='api.bitflyer.jp', port=443): Read timed out. (read timeout=10)
292
-
293
-
294
-
295
- During handling of the above exception, another exception occurred:
296
-
297
-
298
-
299
- File "C:/pythonfiles/price_check/pricecheck04-easyorder/arb8.py", line 229, in process_get_price
300
-
301
- orderbook = exchange_get.fetch_order_book(target_currency) # ここです。■■■■■■■■■■■■■■
302
-
303
-   File "C:\Users\hogehoge\AppData\Local\Programs\Python\Python36\lib\site-packages\ccxt\bitflyer.py", line 155, in fetch_order_book
304
-
305
- }, params))
306
-
307
- File "C:\Users\hogehoge\AppData\Local\Programs\Python\Python36\lib\site-packages\ccxt\base\exchange.py", line 306, in request
308
-
309
- return self.fetch2(path, api, method, params, headers, body)
310
-
311
- File "C:\Users\hogehoge\AppData\Local\Programs\Python\Python36\lib\site-packages\ccxt\base\exchange.py", line 303, in fetch2
312
-
313
- return self.fetch(request['url'], request['method'], request['headers'], request['body'])
314
-
315
- File "C:\Users\hogehoge\AppData\Local\Programs\Python\Python36\lib\site-packages\ccxt\base\exchange.py", line 367, in fetch
316
-
317
- self.raise_error(RequestTimeout, method, url, e)
318
-
319
- File "C:\Users\hogehoge\AppData\Local\Programs\Python\Python36\lib\site-packages\ccxt\base\exchange.py", line 288, in raise_error
320
-
321
- raise exception_type(output)
322
-
323
-
324
-
325
- ccxt.base.errors.RequestTimeout: bitflyer GET https://api.bitflyer.jp/v1/getboard?product_code=BTC_JPY HTTPSConnectionPool(host='api.bitflyer.jp', port=443): Read timed out. (read timeout=10)
326
-
327
-
328
-
329
- Process finished with exit code 1
330
-
331
- ```

5

ほそく4

2018/05/28 04:40

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -20,7 +20,11 @@
20
20
 
21
21
  例外による無視が出来れば良いのですが、exceptionが出来ません。
22
22
 
23
- またtry文にこだわっているつもりはありません。
23
+ またtry文にこだわっているつもりはありません。ccxt.RequestTimeoutが使えたらいいと思っています。
24
+
25
+
26
+
27
+ 大変お手数をおかけします。よろしくお願いします。
24
28
 
25
29
 
26
30
 

4

ほそく3

2018/05/23 02:04

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -72,10 +72,22 @@
72
72
 
73
73
  ```ここに言語を入力
74
74
 
75
+ 1つめ
76
+
75
77
  raise exception_type(output)
76
78
 
77
79
  ccxt.base.errors.RequestTimeout: zaif POST https://api.zaif.jp/tapi HTTPSConnectionPool(host='api.zaif.jp', port=443): Read timed out. (read timeout=10)
78
80
 
81
+
82
+
83
+ 2つめ
84
+
85
+ raise ReadTimeoutError(self, url, "Read timed out. (read timeout=%s)" % timeout_value)
86
+
87
+ urllib3.exceptions.ReadTimeoutError: HTTPSConnectionPool(host='api.bitflyer.jp', port=443): Read timed out. (read timeout=10)
88
+
89
+
90
+
79
91
  ```
80
92
 
81
93
 
@@ -170,7 +182,7 @@
170
182
 
171
183
 
172
184
 
173
- **今回エラーが出ているcreateorderのtimeout**
185
+ **今回エラーが出ているcreateorderのtimeoutにおける2つの対応推奨案**
174
186
 
175
187
 
176
188
 
@@ -179,3 +191,137 @@
179
191
  update the .orders cache with a call to fetchOrders, fetchOpenOrders, fetchClosedOrders to check if the request to place the order has succeeded and the order is now open
180
192
 
181
193
  if the order is not 'open' the user should fetchBalance to check if the balance has changed since the order was created on the first run and then was filled and closed by the time of the second check. Note that fetchBalance relies on the .orders cache for balance inference and thus should only be called after updating the cache!
194
+
195
+
196
+
197
+
198
+
199
+ 同じソース箇所で出た2つ目のエラー
200
+
201
+
202
+
203
+ ```ここに言語を入力
204
+
205
+ raise ReadTimeoutError(self, url, "Read timed out. (read timeout=%s)" % timeout_value)
206
+
207
+ urllib3.exceptions.ReadTimeoutError: HTTPSConnectionPool(host='api.bitflyer.jp', port=443): Read timed out. (read timeout=10)
208
+
209
+ ```
210
+
211
+
212
+
213
+ **エラー詳細**
214
+
215
+
216
+
217
+ ```ここに言語を入力
218
+
219
+ Traceback (most recent call last):
220
+
221
+
222
+
223
+ socket.timeout: The read operation timed out
224
+
225
+
226
+
227
+ During handling of the above exception, another exception occurred:
228
+
229
+
230
+
231
+ Traceback (most recent call last):
232
+
233
+ File "C:\Users\hogehoge\AppData\Local\Programs\Python\Python36\lib\site-packages\requests\adapters.py", line 440, in send
234
+
235
+ timeout=timeout
236
+
237
+ File "C:\Users\hogehoge\AppData\Local\Programs\Python\Python36\lib\site-packages\urllib3\connectionpool.py", line 639, in urlopen
238
+
239
+ _stacktrace=sys.exc_info()[2])
240
+
241
+ File "C:\Users\hogehoge\AppData\Local\Programs\Python\Python36\lib\site-packages\urllib3\util\retry.py", line 357, in increment
242
+
243
+ raise six.reraise(type(error), error, _stacktrace)
244
+
245
+ File "C:\Users\hogehoge\AppData\Local\Programs\Python\Python36\lib\site-packages\urllib3\packages\six.py", line 686, in reraise
246
+
247
+ raise value
248
+
249
+ File "C:\Users\hogehoge\AppData\Local\Programs\Python\Python36\lib\site-packages\urllib3\connectionpool.py", line 601, in urlopen
250
+
251
+ chunked=chunked)
252
+
253
+ File "C:\Users\hogehoge\AppData\Local\Programs\Python\Python36\lib\site-packages\urllib3\connectionpool.py", line 389, in _make_request
254
+
255
+ self._raise_timeout(err=e, url=url, timeout_value=read_timeout)
256
+
257
+ File "C:\Users\hogehoge\AppData\Local\Programs\Python\Python36\lib\site-packages\urllib3\connectionpool.py", line 309, in _raise_timeout
258
+
259
+ raise ReadTimeoutError(self, url, "Read timed out. (read timeout=%s)" % timeout_value)
260
+
261
+ urllib3.exceptions.ReadTimeoutError: HTTPSConnectionPool(host='api.bitflyer.jp', port=443): Read timed out. (read timeout=10)
262
+
263
+
264
+
265
+ During handling of the above exception, another exception occurred:
266
+
267
+
268
+
269
+ Traceback (most recent call last):
270
+
271
+ File "C:\Users\hogehoge\AppData\Local\Programs\Python\Python36\lib\site-packages\ccxt\base\exchange.py", line 357, in fetch
272
+
273
+ proxies=self.proxies
274
+
275
+ File "C:\Users\hogehoge\AppData\Local\Programs\Python\Python36\lib\site-packages\requests\sessions.py", line 508, in request
276
+
277
+ resp = self.send(prep, **send_kwargs)
278
+
279
+ File "C:\Users\hogehoge\AppData\Local\Programs\Python\Python36\lib\site-packages\requests\sessions.py", line 618, in send
280
+
281
+ r = adapter.send(request, **kwargs)
282
+
283
+ File "C:\Users\hogehoge\AppData\Local\Programs\Python\Python36\lib\site-packages\requests\adapters.py", line 521, in send
284
+
285
+ raise ReadTimeout(e, request=request)
286
+
287
+ requests.exceptions.ReadTimeout: HTTPSConnectionPool(host='api.bitflyer.jp', port=443): Read timed out. (read timeout=10)
288
+
289
+
290
+
291
+ During handling of the above exception, another exception occurred:
292
+
293
+
294
+
295
+ File "C:/pythonfiles/price_check/pricecheck04-easyorder/arb8.py", line 229, in process_get_price
296
+
297
+ orderbook = exchange_get.fetch_order_book(target_currency) # ここです。■■■■■■■■■■■■■■
298
+
299
+   File "C:\Users\hogehoge\AppData\Local\Programs\Python\Python36\lib\site-packages\ccxt\bitflyer.py", line 155, in fetch_order_book
300
+
301
+ }, params))
302
+
303
+ File "C:\Users\hogehoge\AppData\Local\Programs\Python\Python36\lib\site-packages\ccxt\base\exchange.py", line 306, in request
304
+
305
+ return self.fetch2(path, api, method, params, headers, body)
306
+
307
+ File "C:\Users\hogehoge\AppData\Local\Programs\Python\Python36\lib\site-packages\ccxt\base\exchange.py", line 303, in fetch2
308
+
309
+ return self.fetch(request['url'], request['method'], request['headers'], request['body'])
310
+
311
+ File "C:\Users\hogehoge\AppData\Local\Programs\Python\Python36\lib\site-packages\ccxt\base\exchange.py", line 367, in fetch
312
+
313
+ self.raise_error(RequestTimeout, method, url, e)
314
+
315
+ File "C:\Users\hogehoge\AppData\Local\Programs\Python\Python36\lib\site-packages\ccxt\base\exchange.py", line 288, in raise_error
316
+
317
+ raise exception_type(output)
318
+
319
+
320
+
321
+ ccxt.base.errors.RequestTimeout: bitflyer GET https://api.bitflyer.jp/v1/getboard?product_code=BTC_JPY HTTPSConnectionPool(host='api.bitflyer.jp', port=443): Read timed out. (read timeout=10)
322
+
323
+
324
+
325
+ Process finished with exit code 1
326
+
327
+ ```

3

ほそく2

2018/05/23 02:03

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -19,6 +19,8 @@
19
19
 
20
20
 
21
21
  例外による無視が出来れば良いのですが、exceptionが出来ません。
22
+
23
+ またtry文にこだわっているつもりはありません。
22
24
 
23
25
 
24
26
 
@@ -78,6 +80,74 @@
78
80
 
79
81
 
80
82
 
83
+ 参考にしたtry 文
84
+
85
+ ```ここに言語を入力
86
+
87
+ from_datetime = '2017-01-01 00:00:00'
88
+
89
+ from_timestamp = exchange.parse8601(from_datetime)
90
+
91
+
92
+
93
+ # -----------------------------------------------------------------------------
94
+
95
+
96
+
97
+ now = exchange.milliseconds()
98
+
99
+
100
+
101
+ # -----------------------------------------------------------------------------
102
+
103
+
104
+
105
+ data = []
106
+
107
+
108
+
109
+ while from_timestamp < now:
110
+
111
+
112
+
113
+ try:
114
+
115
+
116
+
117
+ print(exchange.milliseconds(), 'Fetching candles starting from', exchange.iso8601(from_timestamp))
118
+
119
+ ohlcvs = exchange.fetch_ohlcv('BTC/USD', '5m', from_timestamp)
120
+
121
+ print(exchange.milliseconds(), 'Fetched', len(ohlcvs), 'candles')
122
+
123
+ first = ohlcvs[0][0]
124
+
125
+ last = ohlcvs[-1][0]
126
+
127
+ print('First candle epoch', first, exchange.iso8601(first))
128
+
129
+ print('Last candle epoch', last, exchange.iso8601(last))
130
+
131
+ from_timestamp += len(ohlcvs) * minute * 5
132
+
133
+ data += ohlcvs
134
+
135
+
136
+
137
+ except (ccxt.ExchangeError, ccxt.AuthenticationError, ccxt.ExchangeNotAvailable, ccxt.RequestTimeout) as error:
138
+
139
+
140
+
141
+ print('Got an error', type(error).__name__, error.args, ', retrying in', hold, 'seconds...')
142
+
143
+ time.sleep(hold)
144
+
145
+ ```
146
+
147
+
148
+
149
+
150
+
81
151
  RequestTimeoutについての説明
82
152
 
83
153
 

2

補足2

2018/05/23 01:56

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -19,6 +19,24 @@
19
19
 
20
20
 
21
21
  例外による無視が出来れば良いのですが、exceptionが出来ません。
22
+
23
+
24
+
25
+ 参考URL:
26
+
27
+
28
+
29
+ https://code.i-harness.com/ja/q/b268c
30
+
31
+ https://teratail.com/questions/109954
32
+
33
+
34
+
35
+ ポイント:
36
+
37
+
38
+
39
+ 例外(エラー)が発生しそうな処理「だけ」try: except:で囲う
22
40
 
23
41
 
24
42
 

1

補足2

2018/05/23 01:48

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -60,11 +60,9 @@
60
60
 
61
61
 
62
62
 
63
- 英語が読めずヒントが書かれいると思うですが理解できません。泣
63
+ RequestTimeoutついての説明
64
64
 
65
65
 
66
-
67
- RequestTimeout
68
66
 
69
67
  This exception is raised when the connection with the exchange fails or data is not fully received in a specified amount of time. This is controlled by the timeout option. When a RequestTimeout is raised, the user doesn't know the outcome of a request (whether it was accepted by the exchange server or not).
70
68
 
@@ -82,6 +80,12 @@
82
80
 
83
81
  an OrderNotFound exception is raised, which means the order was either already canceled on the first attempt or has been executed (filled and closed) in the meantime between the two attempts. Note, that the order will still have an 'open' status in the .orders cache. To determine the actual order status you'll need to call fetchOrder to update the cache properly (where available from the exchange). If the fetchOrder method is 'emulated' the ccxt library will mark the order as 'closed'. The user has to call fetchBalance and set the order status to 'canceled' manually if the balance hasn't changed (a trade didn't not occur).
84
82
 
83
+
84
+
85
+ **今回エラーが出ているcreateorderのtimeout**
86
+
87
+
88
+
85
89
  if a request to createOrder fails with a RequestTimeout the user should:
86
90
 
87
91
  update the .orders cache with a call to fetchOrders, fetchOpenOrders, fetchClosedOrders to check if the request to place the order has succeeded and the order is now open