我试图使用browsermob-proxy来监视selenium测试的所有请求和响应。在我的例子中,我使用selenium框架在jenkins上的docker映像中运行docker测试。我正在使用以下版本:
还有java openjdk-8-jdk。
在py.test代码中,我有以下行来创建和启动服务器:
proxyserver = Server(
path="/root/tests/bsp_usecase_tests/bin/browsermob-proxy",
options={'port': 8090}
)
proxyserver.start()
driverproxy = proxyserver.create_proxy() # line 127但在最后一行中,我得到了以下错误:
conftest.py:127: in basedriver
driverproxy = proxyserver.create_proxy()
/usr/local/lib/python2.7/dist-packages/browsermobproxy/server.py:40: in create_proxy
client = Client(self.url[7:], params)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <browsermobproxy.client.Client object at 0x7f1a5f73f1d0>
url = 'localhost:8090', params = {}, options = {}
def __init__(self, url, params=None, options=None):
"""
Initialises a new Client object
:param url: This is where the BrowserMob Proxy lives
:param params: URL query (for example httpProxy and httpsProxy vars)
:param options: Dictionary that can contain the port of an existing
proxy to use (for example 'existing_proxy_port_to_use')
"""
params = params if params is not None else {}
options = options if options is not None else {}
self.host = "http://" + url
if params:
urlparams = "?" + unquote(urlencode(params))
else:
urlparams = ""
if 'existing_proxy_port_to_use' in options:
self.port = options['existing_proxy_port_to_use']
else:
resp = requests.post('%s/proxy' % self.host + urlparams)
content = resp.content.decode('utf-8')
try:
jcontent = json.loads(content)
except Exception as e:
raise Exception("Could not read Browsermob-Proxy json\n"
> "Another server running on this port?\n%s..." % content[:512])
E Exception: Could not read Browsermob-Proxy json
E Another server running on this port?
E <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
E <html><head>
E <meta type="copyright" content="Copyright (C) 1996-2016 The Squid Software Foundation and contributors">
E <meta http-equiv="Content-Type" CONTENT="text/html; charset=utf-8">
E <title>ERROR: The requested URL could not be retrieved</title>
E <style type="text/css"><!--
E /*
E * Copyright (C) 1996-2016 The Squid Software Foundation and contributors
E *
E * Squid software is distributed under GPLv2+ license and incl...
/usr/local/lib/python2.7/dist-packages/browsermobproxy/client.py:37: Exception也许我忘了把重要文件复制到码头图像里了?
我为browsermob-proxy设置了以下设置(除了pip安装):
bsp_usecase_tests/bin:
browsermob-proxy
bsp_usecase_tests/lib:
browsermob-dist-2.1.4.jar也就是说,我已经将文件browsermob-proxy复制到bin中,将文件browsermob-dist-2.1.4.jar复制到lib文件夹中。而且,服务器本身似乎正在启动和运行。但是当我试图获取用于selenium驱动程序的代理信息时,我会发现这个奇怪的错误.
有什么想法我做错了什么,或者遗漏了什么?
发布于 2018-08-20 09:17:36
在我看来这个港口已经在使用了。您可以检查端口是否正在使用lsof,然后在使用时将其关闭。您可以使用lsof -i:8090进行检查
编辑:您已经在这个线程- How to fix 'Address already in use' error with browsermob-proxy?中这样做了。
我会用
proxyserver = Server(
path="/root/tests/bsp_usecase_tests/bin/browsermob-proxy",
options={'existing_proxy_port_to_use': 8090})这样就行了。
Browsermob中的内部代码正在'options'字典'existing_proxy_port_to_use'中查找密钥,否则将使用默认的空字典。
https://stackoverflow.com/questions/51824178
复制相似问题