Я делаю быстрый тест на python, selenium, django и heroku на Google и возвращаюсь к шаблону. Я беру тайм-аут ошибки h12, все мои приложения с одинаковой ошибкой, я не уверен, как настроитьэто в моем сценарии, я не могу установить рабочий в фоновом режиме.
ошибка:
2018-10-20T02:06:48.131091+00:00 heroku[router]: at=error code=H12
desc="Request timeout" method=POST path="/" host=testeseleniu.herokuapp.com
request_id=74b149
f3-48dc-4e1c-97f3-616d3564cc8c fwd="201.81.178.239" dyno=web.1 connect=1ms
service=30000ms status=503 bytes=0 protocol=https
View.py:
from django.shortcuts import render
from django.views import View
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
import os
class consuappView(View):
def get(self, request):
return render(request, 'consuapp/consulta.html')
def post(self, request):
chrome_exec_shim = os.environ.get("GOOGLE_CHROME_BIN", "chromedriver")
chrome_options = webdriver.ChromeOptions()
chrome_options.binary_location = chrome_exec_shim
chrome_options.add_argument('--headless')
chrome_options.add_argument('--no-sandbox')
self.driver = webdriver.Chrome('/app/.chromedriver/bin/chromedriver',
chrome_options=chrome_options)
self.campo_cep_site = request.POST['cep']
self.campo_num_site = request.POST['num']
self.driver.get("https://www.google.com.br")
wait = WebDriverWait(self.driver, 280)
self.google(wait, self.campo_cep_site)
self.driver.close()
return render(request, 'consuapp/consulta.html', {'retorno_consulta':
self.retorno_consulta})
def google(self, wait, campo_cep_site):
wait.until(EC.element_to_be_clickable((By.ID, 'lst-
ib'))).send_keys(campo_cep_site)
wait.until(EC.element_to_be_clickable((By.ID, 'tsf'))).submit()
form_emp = self.driver.find_elements_by_class_name('xpdopen')
self.retorno_consulta = self.driver.find_element_by_xpath(
'//*
[@id="rhs_block"]/div/div[1]/div/div[1]/div[2]/div[2]/
div/div[2]/div/div/div/div[1]').text
Buildpack:
- heroku / python
- https://github.com/heroku/heroku-buildpack-chromedriver.git
- https://github.com/heroku/heroku-buildpack-google-chrome
В localhost все работает, время на консультацию составляет 5,3 секунды.разбилась только герока.