Home > Software design >  Python browsermob proxy with selenium
Python browsermob proxy with selenium

Time:06-15

I'm trying to import the Google HAR file, but this code I wrote gives me this error:

AttributeError: 'ProxyManger' object has no attribute '_ProxyManger__server'. Did you mean: '_ProxyManger__BMP'?

My codes:

import pprint
import time

from browsermobproxy import Server
from selenium import webdriver

class ProxyManger:

    __BMP = "C:/Users/Ender/Desktop/browsermob-proxy-2.1.4/bin/browsermob-proxy.bat"

    def __int__(self):
        self.__server = Server(ProxyManger.__BMP)
        self.__client = None

    def start_server(self):
        self.__server.start()
        return self.__server

    def start_client(self):

        self.__client = self.__server.create_proxy(params={"trustAllServers": "true"})
        return self.__client

    @property
    def client(self):
        return self.__client
    @property
    def server(self):
        return self.__server
if "__main__" == __name__:
    proxy = ProxyManger()
    server = proxy.start_server()
    client = proxy.start_client()
    client.new_har("google.com")
    print(client.proxy)
    options = webdriver.ChromeOptions()
    options.add_argument("--proxy-server={}".format(client.proxy))
    driver = webdriver.Chrome(chrome_options=options)
    driver.get("https://www.google.com/")
    time.sleep(3)

    pprint.pprint(client.har)
    server.stop()

I don't understand where I went wrong, what is the source of the problem and how do I need to fix it? I would be glad if you help. have a nice day

CodePudding user response:

The __init__ function is written wrong, you have __int__ it's suposed to be __init__ since it does't enter the init function it does't create the _server atribute

  • Related