我正在尝试使用 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)
如果我删除“proxys=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 结果。