1

我试图向受保护的网页发出请求,因此我试图在QAuthenticator()的帮助下进行身份验证。不过,我得到以下错误:TypeError:本地Qt信号不可调用

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) 

什么我错在这里做什么?

回答

3

如错误信息所示,您不能调用PyQt信号。相反,你必须使用emit()方法:

mgr.authenticationRequired.emit(mgr.get(response), auth) 
0

你为什么要发出的信号?我对该协议的理解是,当跨越网络的服务器需要认证时,QNAM将发出该信号。你的程序应该连接到该信号,而不是发出它。 “连接到这个信号的插槽应该填充认证对象中内容的凭证(可以通过检查回复对象来确定)。”我可能是错误的,你正在尝试。