contentEncodingError when opening website in Firefox using selenium and python3

148 Views Asked by At

I'm trying to perform a fairly simple action using Selenium, namely opening google images in Firefox browser. I also use a proxy server running on the localhost.

from selenium.webdriver import Firefox, FirefoxOptions
from selenium.webdriver.firefox.service import Service
from selenium.webdriver.common.proxy import Proxy, ProxyType

options = FirefoxOptions()
service = Service()
options.add_argument("--headless")
options.accept_insecure_certs = True 

proxy = Proxy({
    'httpProxy': proxy_addr,
    'sslProxy': proxy_addr,
    'proxyType': ProxyType.MANUAL
})

options.proxy = proxy

b = Firefox(service=service, options=options)
b.execute("get", {'url': 'http://images.google.com'})

But unfortunately, I'm getting an error like this:

selenium.common.exceptions.WebDriverException: Message: Reached error page: about:neterror?e=contentEncodingError&u=https%3A//images.google.com/%3Fgws_rd%3Dssl&c=UTF-8&d=The%20page%20you%20are%20trying%20to%20view%20cannot%20be%20shown%20because%20it%20uses%20an%20invalid%20or%20unsupported%20form%20of%20compression.

I would be very grateful for any thoughts and advice what exactly might be the problem and at least approximately what should be paid attention to.

I'm using:

debian
firefox-esr
selenium == 4.2.0
geckodriver-v0.31.0
1

There are 1 best solutions below

7
undetected Selenium On

This error message...

selenium.common.exceptions.WebDriverException: Message: Reached error page: about:neterror?e=contentEncodingError&u=https%3A//images.google.com/%3Fgws_rd%3Dssl&c=UTF-8&d=The%20page%20you%20are%20trying%20to%20view%20cannot%20be%20shown%20because%20it%20uses%20an%20invalid%20or%20unsupported%20form%20of%20compression.

...implies that there are some configuration settings mismatch while GeckoDriver initiates/spawns a new Browsing Context i.e. session and is often observed as:

Content Encoding Error


Solution

As per the mozilla support docs you need to try out the following steps:

  • Try to reset the network.http.accept-encoding prefs on the about:config page in case they show as user set (bold). You can open the about:config page via the location/address bar. You can accept the warning and click "I'll be careful" to continue.
  • If you are having Avast Antivirus or Malwarebytes installed, you may need to disable those in the test machine before executing the tests.