How to fix 'Address already in use' error with browsermob-proxy?

ぃ、小莉子 提交于 2019-12-02 04:07:29

We can start the BMP server with required port as given below. server accepts dictionary object for server arguments.

from browsermobproxy import Server
dict={'port':8090}
server = Server(path="C:\\Projects\\BrowserMobProxy\\bin\\browsermob-proxy",options=dict)
server.start()
proxy = server.create_proxy()

from selenium import webdriver
profile  = webdriver.FirefoxProfile()
profile.set_proxy(proxy.selenium_proxy())
driver = webdriver.Firefox(firefox_profile=profile)


proxy.new_har("google")
driver.get("http://www.google.co.uk")
proxy.har # returns a HAR JSON blob

server.stop()
driver.quit()

Initialize the server with this -

proxyserver =  Server(
       path="/root/tests/bsp_usecase_tests/bin/browsermob-proxy",
       options={'existing_proxy_port_to_use': 8090})

The internal code in Browsermob-Proxy is looking for key in 'options' dictionary named 'existing_proxy_port_to_use', else it uses default i.e. empty dictionary.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!