質問編集履歴

1

①エラーメッセージの追加 ②logの追加 ③問題が発生していると考えられるview関数の貼り付け

2018/11/04 00:33

投稿

Piyohiko
Piyohiko

スコア10

test CHANGED
File without changes
test CHANGED
@@ -54,26 +54,246 @@
54
54
 
55
55
  ### 発生している問題・エラーメッセージ
56
56
 
57
+ プログラム実施中に、「Application Error」のページが開き画面に以下のメッセージが表示されます。
58
+
59
+
60
+
61
+ 「Application error
62
+
63
+ An error occurred in the application and your page could not be served. If you are the application owner, check your logs for details. You can do this from the Heroku CLI with the command
64
+
65
+ heroku logs --tail」
66
+
67
+
68
+
69
+
70
+
71
+ エラーメッセージの通り、「heroku logs --tail」でlogを確認すると以下のようになっていました。
72
+
73
+
74
+
75
+ 2018-11-03T14:12:59.156146+00:00 heroku[router]: at=info method=GET path="/search/" host=mysiter.herokuapp.com request_id=658b4dc8-3432-4064-bf84-e7f55b6089b8 fwd="114.160.109.65" dyno=web.1 connect=0ms service=7ms status=200 bytes=1239 protocol=https
76
+
77
+ 2018-11-03T14:12:59.152367+00:00 app[web.1]: 10.9.193.73 - - [03/Nov/2018:23:12:59 +0900] "GET /search/ HTTP/1.1" 200 868 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.77 Safari/537.36"
78
+
79
+ 2018-11-03T14:13:34.996457+00:00 heroku[router]: at=error code=H12 desc="Request timeout" method=POST path="/search/results/" host=mysiter.herokuapp.com request_id=f93bc643-5073-4cf6-bd0f-679c76972981 fwd="114.160.109.65" dyno=web.1 connect=0ms service=30001ms status=503 bytes=0 protocol=https
80
+
81
+ 2018-11-03T14:13:35.250500+00:00 app[web.1]: Internal Server Error: /search/results/
82
+
83
+ 2018-11-03T14:13:35.250514+00:00 app[web.1]: Traceback (most recent call last):
84
+
85
+ 2018-11-03T14:13:35.250535+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/django/core/handlers/exception.py", line 34, in inner
86
+
87
+ 2018-11-03T14:13:35.250537+00:00 app[web.1]: response = get_response(request)
88
+
89
+ 2018-11-03T14:13:35.250540+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/django/core/handlers/base.py", line 126, in _get_response
90
+
91
+ 2018-11-03T14:13:35.250543+00:00 app[web.1]: response = self.process_exception_by_middleware(e, request)
92
+
93
+ 2018-11-03T14:13:35.250545+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/django/core/handlers/base.py", line 124, in _get_response
94
+
95
+ 2018-11-03T14:13:35.250547+00:00 app[web.1]: response = wrapped_callback(request, *callback_args, **callback_kwargs)
96
+
97
+ 2018-11-03T14:13:35.250549+00:00 app[web.1]: File "/app/search/views.py", line 19, in Results
98
+
99
+ 2018-11-03T14:13:35.250551+00:00 app[web.1]: driver = webdriver.Chrome("/app/.apt/usr/bin/google-chrome") # Chromeを動かすドライバを読み込み
100
+
101
+ 2018-11-03T14:13:35.250553+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/selenium/webdriver/chrome/webdriver.py", line 68, in __init__
102
+
103
+ 2018-11-03T14:13:35.250554+00:00 app[web.1]: self.service.start()
104
+
105
+ 2018-11-03T14:13:35.250556+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/selenium/webdriver/common/service.py", line 104, in start
106
+
107
+ 2018-11-03T14:13:35.250558+00:00 app[web.1]: raise WebDriverException("Can not connect to the Service %s" % self.path)
108
+
109
+ 2018-11-03T14:13:35.250559+00:00 app[web.1]: selenium.common.exceptions.WebDriverException: Message: Can not connect to the Service /app/.apt/usr/bin/google-chrome
110
+
111
+
112
+
113
+
114
+
115
+
116
+
117
+ ### 該当のソースコード
118
+
119
+
120
+
121
+ 以下がview関数の詳細で、Results(request)の際にエラーを起こしており、
122
+
123
+ これがSeleniumを実行中に時間がかかりすぎて、Timeoutになっているのではないかと考えています。
124
+
125
+
126
+
127
+ ```python3
128
+
129
+ rom django.shortcuts import render
130
+
131
+ from django.http import HttpResponse
132
+
133
+ from django.urls import reverse
134
+
135
+ from django.shortcuts import get_object_or_404, render
136
+
137
+ from django.http import HttpResponseRedirect
138
+
139
+
140
+
141
+ #検索するようにimportしたモジュール
142
+
143
+ import requests
144
+
145
+ from bs4 import BeautifulSoup
146
+
147
+ import csv
148
+
149
+ from selenium import webdriver #Selenium Webdriverをインポートして
150
+
151
+ from selenium.webdriver.support.select import Select
152
+
153
+ from selenium.webdriver.common.keys import Keys
154
+
155
+
156
+
157
+ def Index(request):
158
+
159
+ return render(request , 'search/index.html')
160
+
161
+
162
+
163
+ def Results(request):
164
+
165
+ driver = webdriver.Chrome("/app/.apt/usr/bin/google-chrome") # Chromeを動かすドライバを読み込み
166
+
167
+ #driver = webdriver.Chrome("/usr/local/bin/chromedriver") # Chromeを動かすドライバを読み込み
168
+
169
+ driver.get("https://www.reifen.de") # サイトを開く!
170
+
171
+
172
+
173
+ # 検索する項目を取得
174
+
175
+ elem_search_cate = driver.find_element_by_xpath(
176
+
177
+ '//*[@id="tires-configurator-form"]/div[2]/div[1]/div[2]/div/select') # タイヤカテゴリ選択部分を取得
178
+
179
+ elem_search_section = driver.find_element_by_xpath('//*[@id="tire-width"]') # タイヤsection選択部分を取得
180
+
181
+ elem_search_ratio = driver.find_element_by_xpath('//*[@id="tire-height"]') # タイヤratio選択部分を取得
182
+
183
+ elem_search_inch = driver.find_element_by_xpath('//*[@id="tire-diameter"]') # タイヤinch選択部分を取得
184
+
185
+ elem_search_btn = driver.find_element_by_xpath('//*[@id="tires-configurator-form"]/div[3]/div/button') # 検索ボタンを取得
186
+
187
+
188
+
189
+ #categoryを選択するパート
190
+
191
+ #110=夏タイヤ / 120=冬タイヤ / 130=オールシーズン
192
+
193
+
194
+
195
+ cate = request.POST.get('category')
196
+
197
+
198
+
199
+ categories= {"summer":110, "winter":120, "allseason":130}
200
+
201
+
202
+
203
+ text_cate = str(categories[cate])
204
+
205
+
206
+
207
+ select = Select(elem_search_cate)
208
+
209
+ select.select_by_value(text_cate)
210
+
211
+
212
+
213
+ #sectionを選択するパート
214
+
215
+
216
+
217
+ text_section = request.POST.get('section')
218
+
219
+ select = Select(elem_search_section)
220
+
221
+ select.select_by_value(text_section)
222
+
223
+
224
+
225
+ #ratioを選択するパート
226
+
227
+
228
+
229
+ text_ratio = request.POST.get('ratio')
230
+
231
+ select = Select(elem_search_ratio)
232
+
233
+ select.select_by_value(text_ratio)
234
+
235
+
236
+
237
+ #inchを選択するパート
238
+
239
+
240
+
241
+ text_inch = request.POST.get('inch')
242
+
243
+ select = Select(elem_search_inch)
244
+
245
+ select.select_by_value(text_inch)
246
+
247
+
248
+
249
+ elem_search_btn.send_keys(Keys.ENTER)
250
+
251
+
252
+
253
+ #ここで次のページに移動
254
+
255
+
256
+
257
+ html_a = driver.current_url
258
+
259
+ seleniumrequest = requests.get(html_a)
260
+
261
+ content = seleniumrequest.content
262
+
263
+
264
+
265
+ soup = BeautifulSoup(content, "html.parser")
266
+
267
+
268
+
269
+ elements_a = soup.find_all(class_="product-list-item product-list-item-top standby-status")
270
+
271
+
272
+
273
+ result = [['name', 'price', 'RRC labeling', 'WET labeling', 'noise labeling']]
274
+
275
+ for element in elements_a:
276
+
277
+ product_name = element.find(class_="search-result-name").text
278
+
279
+ product_price = element.find(class_="search-result-price-lower").text
280
+
281
+ product = [product_name.lstrip(), product_price.lstrip().replace('\n', '')]
282
+
283
+
284
+
285
+ result.append(product)
286
+
287
+ driver.close()
288
+
289
+
290
+
291
+ return render(request, 'search/results.html', {'result': result, 'section':text_section, 'ratio':text_ratio, 'category':cate, 'inch':text_inch} )
292
+
57
293
 
58
294
 
59
295
  ```
60
296
 
61
- エラーメッセージ
62
-
63
- ```
64
-
65
-
66
-
67
- ### 該当のソースコード
68
-
69
-
70
-
71
- ```ここに言語名を入力
72
-
73
- ソースコード
74
-
75
- ```
76
-
77
297
 
78
298
 
79
299
  ### 試したこと