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將發出該信號。你的程序應該連接到該信號,而不是發出它。 「連接到這個信號的插槽應該填充認證對象中內容的憑證(可以通過檢查回覆對象來確定)。」我可能是錯誤的,你正在嘗試。