我正在尝试使用Browsermob代理来捕获有关请求的信息。 让它适用于没有授权标头的HTTP请求和HTTPS请求。
if(product == 'Product'):
headers = {
'Authorization': 'Bearer %s' % accessToken()
}
http_proxy = "http://localhost:" + str(self.proxy.port)
https_proxy = "https://localhost:" + str(self.proxy.port)
ftp_proxy = "ftp://localhost:" + str(self.proxy.port)
proxyDict = {
"http" : http_proxy,
"ftp" : ftp_proxy,
"https" : https_proxy
}
fullurl = baseurl
fullurl += '/'
fullurl += baseuri
logger.console("fullurl: '%s'" % fullurl)
response = requests.request(method,fullurl,proxies=proxyDict,verify=False,data=payload,headers=headers)
如果我删除'proxies = proxyDict',请求会通过。如果我通过代理,请求似乎超时,我得到了以下异常:
Exception: Error creating SSLEngine for connection to client to impersonate upstream host: null
at net.lightbody.bmp.mitm.manager.ImpersonatingMitmManager.clientSslEngineFor(ImpersonatingMitmManager.java:227) ~[browsermob-dist-2.1.0.jar:?]
at org.littleshoot.proxy.impl.ProxyToServerConnection$3.execute(ProxyToServerConnection.java:739) ~[browsermob-dist-2.1.0.jar:?]
at org.littleshoot.proxy.impl.ConnectionFlow.doProcessCurrentStep(ConnectionFlow.java:140) ~[browsermob-dist-2.1.0.jar:?]
at org.littleshoot.proxy.impl.ConnectionFlow.processCurrentStep(ConnectionFlow.java:128) ~[browsermob-dist-2.1.0.jar:?]
at org.littleshoot.proxy.impl.ConnectionFlow.advance(ConnectionFlow.java:90) ~[browsermob-dist-2.1.0.jar:?]
at org.littleshoot.proxy.impl.ConnectionFlowStep.onSuccess(ConnectionFlowStep.java:83) ~[browsermob-dist-2.1.0.jar:?]
at org.littleshoot.proxy.impl.ConnectionFlow$2.operationComplete(ConnectionFlow.java:149) ~[browsermob-dist-2.1.0.jar:?]
at io.netty.util.concurrent.DefaultPromise.notifyListener0(DefaultPromise.java:683) [browsermob-dist-2.1.0.jar:?]
at io.netty.util.concurrent.DefaultPromise.notifyLateListener(DefaultPromise.java:624) [browsermob-dist-2.1.0.jar:?]
at io.netty.util.concurrent.DefaultPromise.addListener(DefaultPromise.java:139) [browsermob-dist-2.1.0.jar:?]
at io.netty.channel.DefaultChannelPromise.addListener(DefaultChannelPromise.java:93) [browsermob-dist-2.1.0.jar:?]
at io.netty.channel.DefaultChannelPromise.addListener(DefaultChannelPromise.java:28) [browsermob-dist-2.1.0.jar:?]
at org.littleshoot.proxy.impl.ConnectionFlow.doProcessCurrentStep(ConnectionFlow.java:140) [browsermob-dist-2.1.0.jar:?]
at org.littleshoot.proxy.impl.ConnectionFlow.access$000(ConnectionFlow.java:14) [browsermob-dist-2.1.0.jar:?]
at org.littleshoot.proxy.impl.ConnectionFlow$1.run(ConnectionFlow.java:124) [browsermob-dist-2.1.0.jar:?]
at io.netty.util.concurrent.PromiseTask$RunnableAdapter.call(PromiseTask.java:38) [browsermob-dist-2.1.0.jar:?]
at io.netty.util.concurrent.PromiseTask.run(PromiseTask.java:73) [browsermob-dist-2.1.0.jar:?]
at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:358) [browsermob-dist-2.1.0.jar:?]
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:374) [browsermob-dist-2.1.0.jar:?]
at io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:112) [browsermob-dist-2.1.0.jar:?]
at java.lang.Thread.run(Unknown Source) [?:1.8.0_91]
Caused by: java.lang.NullPointerException
at com.google.common.base.Preconditions.checkNotNull(Preconditions.java:212) ~[browsermob-dist-2.1.0.jar:?]
at com.google.common.cache.LocalCache.get(LocalCache.java:3952) ~[browsermob-dist-2.1.0.jar:?]
at com.google.common.cache.LocalCache$LocalManualCache.get(LocalCache.java:4790) ~[browsermob-dist-2.1.0.jar:?]
at net.lightbody.bmp.mitm.manager.ImpersonatingMitmManager.getHostnameImpersonatingSslContext(ImpersonatingMitmManager.java:242) ~[browsermob-dist-2.1.0.jar:?]
at net.lightbody.bmp.mitm.manager.ImpersonatingMitmManager.clientSslEngineFor(ImpersonatingMitmManager.java:223) ~[browsermob-dist-2.1.0.jar:?]
... 20 more
browsermob是否会处理这样的授权,或者我只是做错了?是否有其他代理解决方案可能更适合这个?我希望使用har结果。
答案 0 :(得分:0)
从错误日志中,我猜测它是两个问题之一:
浏览器中的错误。尝试升级到较新版本
域名浏览器认为它正在运行,以及您正在连接的域名之间存在不匹配。尝试切换到您的显式IP作为主机名 - 即:" 127.0.0.1"而不是" localhost"
这似乎与授权标题无关。