Error initializing Selenium with FirefoxOptions: 502 Bad Gateway

41 Views Asked by At

I have a Python class that initializes Selenium-wire for web scraping. Below is a simplified version:

class SeleniumAPI:
    __INSTAGRAM_HOMEPAGE = "https://www.instagram.com/"

    def __init__(self) -> None:

        self.browser = None

    def create_browser(self):
        try:

            options = webdriver.FirefoxOptions()
            # options.set_preference(
            #     "general.useragent.override", self.account.agent.get("browser_agent")
            # )

            options.add_argument("--headless")
            browser = webdriver.Firefox(
                options=options
            )

            self.browser = browser
        except Exception as err:
            raise err

I then utilize this class within another class as follows:

class SeleniumFetcher(FetcherInterface):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.crawler = self.initialize_crawler()

    def setter_keyword(self, keyword):
        self.keywords = {'lang': keyword[0], 'keyword': keyword[1], 'pop_max_id': keyword[2], 'search_id': keyword[3]}

    def initialize_crawler(self, *args, **kwargs):
        return self.browser_initialization()

    def browser_initialization(self):
        browser = TwitterSearch()
        news_browser = SeleniumAPI()
        news_browser.create_browser()
        if browser.load_user(self.account) and browser.initialize(login=True):
            return browser

However, when executing options = webdriver.FirefoxOptions(), I encounter the following error:

the error has been raised An Error Occurred *** Message: 502 Bad Gateway

502 Bad Gateway

Host Not Found or connection failed

I've changed my network but nothign happend

0

There are 0 best solutions below