mozilla / geckodriver

WebDriver for Firefox
https://firefox-source-docs.mozilla.org/testing/geckodriver/
Mozilla Public License 2.0
7.03k stars 1.51k forks source link

selenium.common.exceptions.WebDriverException: Message: Invalid Host header localhost:50047 exception with selenium and gecko #2163

Closed urec56 closed 3 months ago

urec56 commented 4 months ago

System

Testcase

from selenium.webdriver import Firefox
from selenium.webdriver.firefox.options import Options

opts = Options()
opts.log.level = "trace"
driver = Firefox(options=opts)

or

import time

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.firefox.options import Options

url = 'https://www.youtube.com/watch?v=hVvHAPDX9Kk'

opts = Options()
opts.log.level = "trace"
driver = webdriver.Firefox(options=opts)

both

Stacktrace

Traceback (most recent call last):
  File "/mnt/urec/trash/some/all/PycharmProjects/VideoGrep2/test_parser.py", line 11, in <module>
    driver = webdriver.Firefox(options=opts)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/mnt/urec/trash/some/all/PycharmProjects/VideoGrep2/.venv/lib/python3.11/site-packages/selenium/webdriver/firefox/webdriver.py", line 69, in __init__
    super().__init__(command_executor=executor, options=options)
  File "/mnt/urec/trash/some/all/PycharmProjects/VideoGrep2/.venv/lib/python3.11/site-packages/selenium/webdriver/remote/webdriver.py", line 208, in __init__
    self.start_session(capabilities)
  File "/mnt/urec/trash/some/all/PycharmProjects/VideoGrep2/.venv/lib/python3.11/site-packages/selenium/webdriver/remote/webdriver.py", line 292, in start_session
    response = self.execute(Command.NEW_SESSION, caps)["value"]
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/mnt/urec/trash/some/all/PycharmProjects/VideoGrep2/.venv/lib/python3.11/site-packages/selenium/webdriver/remote/webdriver.py", line 347, in execute
    self.error_handler.check_response(response)
  File "/mnt/urec/trash/some/all/PycharmProjects/VideoGrep2/.venv/lib/python3.11/site-packages/selenium/webdriver/remote/errorhandler.py", line 229, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: Invalid Host header localhost:50047

Trace-level log

This file didn't created

whimboo commented 4 months ago

Thank you for the report. I have some questions:

urec56 commented 4 months ago

I install it for the first time It was local test on my PC I use IPv4 instead of IPv6 because I don't have v6

whimboo commented 4 months ago

Is localhost correctly set to 127.0.0.1? I cannot see why it should fail otherwise.

Please check again if there is really no geckodriver.log file present. It should really be there given that this failure from above comes from geckodriver, and it should have already written content to stdout (as captured by Selenium and piped to that file).

urec56 commented 3 months ago
from selenium.webdriver import Firefox
from selenium.webdriver.firefox.options import Options
from selenium.webdriver.common.by import By

url = sys.argv[1]

opts = Options()
opts.log.level = "trace"
driver = Firefox(options=opts)
driver.get(url)

Am i right?

I don't have any geckodriver.log in my directory image

whimboo commented 3 months ago

Without trace logs I cannot really help. Maybe you could use WireShark to record the HTTP requests / responses with geckodriver? This could give an idea what might go wrong here.

urec56 commented 3 months ago

Ok, I'll check it in few days

whimboo commented 3 months ago

Btw. you can also use a plain curl command to actually get this tested. We have some documentation, which describes what you have to do.

urec56 commented 3 months ago

Sorry. I don't have any time to check this now. If I will, I'll check it and return some info here

whimboo commented 3 months ago

That's fine. I'll close the issue for now and we are happy to reopen in case it is indeed a problem on our side.

urec56 commented 3 months ago

yep