Ошибки SSL при использовании Sauce Labs в Travis CI с веб-тестами Selenium (проект Django)

Пытаемся запустить несколько функциональных тестов для нашего проекта Django, но столкнулись с ошибкой, отладить которую очень сложно. Мы попытались настроить подключение соуса, но наша сборка не удалась. .

Вы можете увидеть результаты сборки, а вот трассировка стека .

======================================================================
ERROR: test_page_load (quote_me.tests.FunctionalTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/opt/python/3.6.3/lib/python3.6/urllib/request.py", line 1318, in do_open
    encode_chunked=req.has_header('Transfer-encoding'))
  File "/opt/python/3.6.3/lib/python3.6/http/client.py", line 1239, in request
    self._send_request(method, url, body, headers, encode_chunked)
  File "/opt/python/3.6.3/lib/python3.6/http/client.py", line 1285, in _send_request
    self.endheaders(body, encode_chunked=encode_chunked)
  File "/opt/python/3.6.3/lib/python3.6/http/client.py", line 1234, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
  File "/opt/python/3.6.3/lib/python3.6/http/client.py", line 1026, in _send_output
    self.send(msg)
  File "/opt/python/3.6.3/lib/python3.6/http/client.py", line 964, in send
    self.connect()
  File "/opt/python/3.6.3/lib/python3.6/http/client.py", line 1400, in connect
    server_hostname=server_hostname)
  File "/opt/python/3.6.3/lib/python3.6/ssl.py", line 407, in wrap_socket
    _context=self, _session=session)
  File "/opt/python/3.6.3/lib/python3.6/ssl.py", line 814, in __init__
    self.do_handshake()
  File "/opt/python/3.6.3/lib/python3.6/ssl.py", line 1068, in do_handshake
    self._sslobj.do_handshake()
  File "/opt/python/3.6.3/lib/python3.6/ssl.py", line 689, in do_handshake
    self._sslobj.do_handshake()
ssl.SSLEOFError: EOF occurred in violation of protocol (_ssl.c:777)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/travis/build/winecountry/quote-me/quote_me/tests.py", line 77, in setUp
    self.selenium = webdriver.Remote(desired_capabilities=capabilities, command_executor="https://%s/wd/hub" % hub_url)
  File "/home/travis/virtualenv/python3.6.3/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 154, in __init__
    self.start_session(desired_capabilities, browser_profile)
  File "/home/travis/virtualenv/python3.6.3/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 243, in start_session
    response = self.execute(Command.NEW_SESSION, parameters)
  File "/home/travis/virtualenv/python3.6.3/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 310, in execute
    response = self.command_executor.execute(driver_command, params)
  File "/home/travis/virtualenv/python3.6.3/lib/python3.6/site-packages/selenium/webdriver/remote/remote_connection.py", line 466, in execute
    return self._request(command_info[0], url, body=data)
  File "/home/travis/virtualenv/python3.6.3/lib/python3.6/site-packages/selenium/webdriver/remote/remote_connection.py", line 528, in _request
    resp = opener.open(request, timeout=self._timeout)
  File "/opt/python/3.6.3/lib/python3.6/urllib/request.py", line 526, in open
    response = self._open(req, data)
  File "/opt/python/3.6.3/lib/python3.6/urllib/request.py", line 544, in _open
    '_open', req)
  File "/opt/python/3.6.3/lib/python3.6/urllib/request.py", line 504, in _call_chain
    result = func(*args)
  File "/opt/python/3.6.3/lib/python3.6/urllib/request.py", line 1361, in https_open
    context=self._context, check_hostname=self._check_hostname)
  File "/opt/python/3.6.3/lib/python3.6/urllib/request.py", line 1320, in do_open
    raise URLError(err)
urllib.error.URLError: <urlopen error EOF occurred in violation of protocol (_ssl.c:777)>

Ошибка указывает мне на строку 77 в tests.py файл, который

self.selenium = webdriver.Remote(desired_capabilities=capabilities, command_executor="https://%s/wd/hub" % hub_url)

Все это основано на коде Трэвиса, и вы можно увидеть наш .travis.yml.

def setUp(self):
    if "TRAVIS" in environ:
        username = environ["SAUCE_USERNAME"]
        access_key = environ["SAUCE_ACCESS_KEY"]
        capabilities = {}
        capabilities["tunnel-identifier"] = environ["TRAVIS_JOB_NUMBER"]
        hub_url = "%s:%s@localhost:4445" % (username, access_key)
        capabilities["build"] = environ["TRAVIS_BUILD_NUMBER"]
        capabilities["tags"] = [environ["TRAVIS_PYTHON_VERSION"], "CI"]
        self.selenium = webdriver.Remote(desired_capabilities=capabilities, command_executor="https://%s/wd/hub" % hub_url)
    else:   
        self.selenium = webdriver.Safari()
        super(FunctionalTestCase, self).setUp()

Похоже на проблему с сертификатом SSL, поэтому я просмотрел no_ssl_bump_domains option, но, похоже, не помогло. Также подумал, что что-то может быть шатким, потому что мы используем команду Django manage.py runserver.

Пожалуйста, дайте мне знать, если вам нужна дополнительная информация, мы будем очень признательны за помощь!


person FyZyX    schedule 13.01.2018    source источник


Ответы (2)


Исправил это, изменив

self.selenium = webdriver.Remote(desired_capabilities=capabilities, command_executor="https://%s/wd/hub" % hub_url)

to

self.selenium = webdriver.Remote(desired_capabilities=capabilities, command_executor="http://%s/wd/hub" % hub_url)

Если вы пропустили это, мы изменили command_executor, чтобы использовать http, а не https.

person FyZyX    schedule 14.01.2018
comment
Спасибо! Я отправил запрос на изменение примера в документации Travis: github.com/travis-ci/docs-travis-ci-com/pull/1700 - person Thomas K; 08.02.2018

Ошибка дает нам подсказку:

File "/opt/python/3.6.3/lib/python3.6/urllib/request.py", line 1318, in do_open
      encode_chunked=req.has_header('Transfer-encoding'))

По-видимому, это проблема encoding. Но поскольку вы используете Travis CI, я бы порекомендовал вам изменить положение аргументов по следующим причинам:

  • Согласно документации WebDriver implementation для selenium.webdriver.remote.webdriver выглядит следующим образом:

    class selenium.webdriver.remote.webdriver.WebDriver(command_executor='http://127.0.0.1:4444/wd/hub', desired_capabilities=None, browser_profile=None, proxy=None, keep_alive=False, file_detector=None, options=None)
    
  • Согласно вашему блоку кода:

    self.selenium = webdriver.Remote(desired_capabilities=capabilities, command_executor="https://%s/wd/hub" % hub_url)
    
  • Возможно, вы пытаетесь:

    self.selenium = webdriver.Remote(command_executor="https://%s/wd/hub" % hub_url, desired_capabilities=capabilities)
    

Примечание . Хотя у нас нет доступа к вашим desired_capabilities

person DebanjanB    schedule 13.01.2018
comment
Я благодарен за помощь, оказалось, что наш исполнитель команд не должен был использовать https, поэтому "https://%s/wd/hub" % hub_url стал "http://%s/wd/hub" % hub_url и бум, больше никаких проблем. - person FyZyX; 14.01.2018