Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/qt/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
pyqt5.6拦截请求不';行不通_Qt_Interceptor_Pyqt5_Qwebpage - Fatal编程技术网

pyqt5.6拦截请求不';行不通

pyqt5.6拦截请求不';行不通,qt,interceptor,pyqt5,qwebpage,Qt,Interceptor,Pyqt5,Qwebpage,我想通过子类QWebEngineUrlRequestInterceptor截取另一个url请求: class RequestInterceptor(QWebEngineUrlRequestInterceptor): def interceptRequest(self,info): print('#################interceptRequest') print(info.requestUrl(),info.firstPartyUrl()

我想通过子类QWebEngineUrlRequestInterceptor截取另一个url请求:

class RequestInterceptor(QWebEngineUrlRequestInterceptor): 
    def interceptRequest(self,info): 
        print('#################interceptRequest')
        print(info.requestUrl(),info.firstPartyUrl(),info.NavigationType,info.resourceType(),info.requestMethod())
        if info.requestUrl().endswith("/jquery.js"):
           info.redirect('/jqueryTest.js')



app = QApplication([]) 
p = QWebEnginePage() 
v = QWebEngineView() 
v.setPage(p) 
p.profile().setRequestInterceptor(RequestInterceptor())
c.registerObject('bridge', p)
url = "http://127.0.0.1:8000/test.html?t=5"
v.setUrl(QUrl(url)) 
v.show() 
app.exec_()
当我运行代码时,拦截器不工作
希望有人能给我帮助,谢谢

附言: 可能是python垃圾收集造成的。因此,我通过修改代码将拦截器存储在Variable中

p.profile().setRequestInterceptor(RequestInterceptor())


仅此而已。

可能是python垃圾收集造成的。因此,我通过修改代码将拦截器存储在变量中:

p.profile().setRequestInterceptor(RequestInterceptor())
致:


仅此而已。

什么是“不起作用”的确切含义?您提出的更改有帮助吗?这是一个与Python相关的问题,这里的更多讨论这个问题似乎仍然存在于PyQt 5.10中。我想知道为什么我自己的尝试失败了,但您给出了正确的解决方案:确保请求拦截器不会过早地收集垃圾。
p.profile().setRequestInterceptor(RequestInterceptor())
interceptor = RequestInterceptor()
p.profile().setRequestInterceptor(interceptor )