TypeError: native Qt signal is not callable

醉酒当歌 提交于 2019-12-11 09:32:13

问题


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

This is a part of my script:

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)

What am I doing wrong here?


回答1:


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)



回答2:


Why do you want to emit the signal? My understanding of the protocol is that the QNAM will emit that signal when a server across the network wants authentication. Your program should connect to that signal, not emit it. "The slot connected to this signal should fill the credentials for the contents (which can be determined by inspecting the reply object) in the authenticator object." I could be wrong about what you are attempting.



来源:https://stackoverflow.com/questions/10618714/typeerror-native-qt-signal-is-not-callable

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!