wkeeling / selenium-wire

Extends Selenium's Python bindings to give you the ability to inspect requests made by the browser.
MIT License
1.9k stars 254 forks source link

AttributeError: 'Chrome' object has no attribute 'backend' #469

Open taytanqbpass opened 2 years ago

taytanqbpass commented 2 years ago

Currently getting this error and i have no clue/leads on how to fix it.

Selenium-wire Version: 4.5.6 Traceback (most recent call last): File "undetected_chromedriver\v2.py", line 623, in del File "seleniumwire\webdriver.py", line 62, in quit AttributeError: 'Chrome' object has no attribute 'backend' Exception ignored in: <function Chrome.del at 0x000002373B378790>

wkeeling commented 2 years ago

Are you able to share the code you're using that generates the error?

taytanqbpass commented 2 years ago
import seleniumwire.undetected_chromedriver.v2 as uc2

def main():
    seleniumwire_options = {
                        'disable_capture': True,
                        'proxy': {
                                    'http': 'http://XXXXX:XXXXX@54.21.60.114:5132',
                                    'https':  'https://XXXXX:XXXXX@54.21.60.114:5132',
                                    'no_proxy': 'localhost,127.0.0.1'
                                }
                    }
    driver = uc2.Chrome(seleniumwire_options=seleniumwire_options)

XXX is my user:pass auth which i have censored. Thanks.

wkeeling commented 2 years ago

Thanks. I've tried reproducing but I don't see the error. The versions I'm running:

selenium-wire==4.5.6
undetected_chromedriver==3.0.6
chromedriver==96.0.4664.45

Can you confirm your versions of undetected_chromedriver and chromedriver are the same as above?

taytanqbpass commented 2 years ago

Hey @wkeeling still no luck on this

i've tried updating all my packages to the latest versions too. really need to get this working since my google login needs proxies for it not to be banned.

here's my versions Selenium Version: 4.1.0 undetected-chromedriver Version: 3.0.6 selenium-wire Version: 4.5.6 chromdriver Version: 96.0.4664.110

image

wkeeling commented 2 years ago

Yes that's odd. I notice that the error is coming from the driver.quit() call but I don't see that call in your example code above. Can you share the code where the driver.quit() call is being made?

taytanqbpass commented 2 years ago

hey there, this is the whole code, i still get the AttributeError: 'Chrome' object has no attribute 'backend' error

import seleniumwire.undetected_chromedriver.v2 as uc2
import time

def main():
    seleniumwire_options = {
        'disable_capture': True,
        'proxy': {
            'http': 'http://XXXX:XXXX@103.7.207.177:64325',
            'https':'https://XXXX:XXXX@103.7.207.177:64325',
            'no_proxy': 'localhost,127.0.0.1'
        }
    }
    driver = uc2.Chrome(seleniumwire_options=seleniumwire_options)
    driver.get('https://www.google.com/')
    time.sleep(50)

if __name__ == '__main__':
    main()
wkeeling commented 2 years ago

Just noticed that quit() is actually being invoked by __del__ on the v2.Chrome instance, presumably when it's cleaned up. I notice you're using Windows so I'll try and reproduce on that (I've been testing on Linux up to now).

taytanqbpass commented 2 years ago

hey there @wkeeling any luck on this? cant really figure it out. Thanks.

wkeeling commented 2 years ago

Sorry for the delay in coming back @taytanqbpass

I've tried reproducing on Windows, using the same code as above but with my own local proxy (I used an instance of mitmproxy running on port 8080 for that):

test_backend.py

import logging
logging.basicConfig(level=logging.INFO)

import seleniumwire.undetected_chromedriver.v2 as uc2
import time

def main():

    seleniumwire_options = {
                        'disable_capture': True,
                        'proxy': {
                             'http': 'http://localhost:8080',
                             'https': 'https://localhost:8080',
                        }
                    }
    driver = uc2.Chrome(seleniumwire_options=seleniumwire_options)
    driver.get('https://www.google.com/')
    time.sleep(50)

if __name__ == '__main__':
    main()

It gives me:

C:\Users\Will\Documents>test_backend.py
INFO:seleniumwire.storage:Using default request storage
INFO:seleniumwire.backend:Created proxy listening on 127.0.0.1:50575
INFO:seleniumwire.undetected_chromedriver.v2:Using undetected_chromedriver.v2
INFO:undetected_chromedriver.patcher:patching driver executable C:\Users\Will\appdata\roaming\undetected_chromedriver\chromedriver.exe

The Google homepage loads without any issue and I don't see any traceback in the terminal after the program completes. I'm using Selenium 4.1.0 and Selenium Wire 4.5.6 with ChromeDriver 96.0.4664.45 and undetected-chromedriver 3.1.3

Could there be something else in your environment that may be causing this problem? Are you able to try with a clean virtualenv?

Respawnz commented 2 years ago

I'm getting the same error on linux, but I found the reason why quit() is being called in my case.

My script had been run under the root user, so the owner of /tmp/.seleniumwire is root, and when I ran the script again under a non-root user, seleniumwire tried to create a file in that directory, and it failed, so quit() was called.

I don't know if @taytanqbpass is in the same situation, but hopefully my case will bring you guys some ideas. @wkeeling

dmquang commented 1 year ago

`python import seleniumwire.undetected_chromedriver as webdriver from selenium.webdriver.common.keys import Keys

proxy = 'fb2642.huyentlc.com:42192:user42192:D3E0'

opt_proxy = { 'proxy': { 'http': 'http://' + proxy.split(':')[0] +':'+ proxy.split(':')[1] + '@' + proxy.split(':')[2] +':'+proxy.split(':')[3], # user:pass@ip:port 'https': 'http://' + proxy.split(':')[0] +':'+ proxy.split(':')[1] + '@' + proxy.split(':')[2] +':'+proxy.split(':')[3],

'no_proxy': 'localhost,127.0.0.1'

    }
}
# print(opt_proxy)

def main(): options = webdriver.ChromeOptions() options.add_argument("--mute-audio") prefs = {"profile.default_content_setting_values.notifications" : 2} options.add_experimental_option("prefs",prefs) options.add_argument("--app=https://www.instagram.com/") options.add_argument("--window-size=475,700") self.driver = webdriver.Chrome(options=options,seleniumwire_options=opt_proxy) self.driver.implicitly_wait(15) if name == 'main': main() ` this is my code but it's not working image here

bengabp commented 1 year ago

Guys I also encountered the same error in my code but this only happens when I keep my code running for more than 4 hours, so it's really hard to figure out how to debug this and my code base is large a bit. Basically what my code does is iterate through a list os numbers , on each Iteration it creates a chrome instance for automation and before starting the next iteration , the previous chrome instance is stopped using driver.quit() I am running this on an azure ubuntu instance.

AttributeError: 'Chrome' object has no attribute 'backend'
Scraping property data for postcode => YO95 1BT. Creating driver...
[Exception Handler] ==> Cause:None | Context:None
Exception ignored in: <function Chrome.__del__ at 0x7f82f8c9c040>
Traceback (most recent call last):
  File "/home/stagnator/home/VirtualEnvironments/scraper/lib/python3.8/site-packages/undetected_chromedriver/__init__.py", line 777, in __del__
  File "/home/stagnator/home/VirtualEnvironments/scraper/lib/python3.8/site-packages/seleniumwire/webdriver.py", line 67, in quit
  File "/home/stagnator/home/VirtualEnvironments/scraper/lib/python3.8/site-packages/undetected_chromedriver/__init__.py", line 740, in __getattribute__
sSuHao commented 1 year ago

I got the same error and dont know why

goyalritik commented 10 months ago

Anyone got any solution?