本文介绍了TypeError:无法调用本机Qt信号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正尝试向受保护的网页发出请求,因此,我正尝试在QAuthenticator()
的帮助下进行身份验证.但是,出现以下错误:
I'm trying to make a request to a protected webpage, so therefore I'm trying to authenticate with help from QAuthenticator()
. However, I get the following error:
mgr.authenticationRequired(response, auth)
TypeError: native Qt signal is not callable
这是我脚本的一部分:
def authenticate(self):
username = 'user'
password = 'pass'
url = 'http://someurl.com'
mgr = QNetworkAccessManager(self)
auth = QAuthenticator()
auth.setUser(username)
auth.setPassword(password)
response = QNetworkRequest()
response.setUrl(QUrl(url))
mgr.authenticationRequired(mgr.get(response), auth)
我在做什么错了?
推荐答案
如错误消息所示,您不能调用PyQt信号.相反,您必须使用emit()
方法:
As the error message indicates, you cannot call PyQt signals. Instead, you have to use the emit()
method:
mgr.authenticationRequired.emit(mgr.get(response), auth)
这篇关于TypeError:无法调用本机Qt信号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!