gpt4 book ai didi

selenium - 如何修复 "Could not read Browsermob-Proxy json"?

转载 作者:行者123 更新时间:2023-12-01 05:53:24 30 4
gpt4 key购买 nike

我正在尝试使用 browsermob-proxy 来监控 selenium 测试的所有请求和响应。在我的例子中,我在 jenkins 上的 docker 图像中使用 py.test 框架运行 selenium 测试.我正在使用以下版本:

  • Selenium ==3.8.0
  • pyvirtualdisplay==0.2.1
  • pytest==3.4.0
  • browsermob-proxy==0.8.0

还有 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

也许我忘记将重要文件复制到 docker 镜像中?

我对 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 驱动程序的代理信息时,出现了这个奇怪的错误...

有什么想法我做错了什么,或者遗漏了什么吗?

最佳答案

在我看来,该端口已被使用。您可以使用 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-Proxy 中的内部代码正在寻找名为 'existing_proxy_port_to_use''options' 字典中的键,否则它使用默认值,即空字典。

关于selenium - 如何修复 "Could not read Browsermob-Proxy json"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51824178/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com