Class: QgsBlockingNetworkRequest¶
- class qgis.core.QgsBlockingNetworkRequest¶
Bases:
PyQt5.QtCore.QObject
A thread safe class for performing blocking (sync) network requests, with full support for QGIS proxy and authentication settings.
This class should be used whenever a blocking network request is required. Unlike implementations which rely on QApplication.processEvents() or creation of a QEventLoop, this class is completely thread safe and can be used on either the main thread or background threads without issue.
Redirects are automatically handled by the class.
After completion of a request, the reply content should be retrieved by calling
getReplyContent()
. This method returns aQgsNetworkReplyContent
container, which is safe and cheap to copy and pass between threads without issue.New in version 3.6.
QgsBlockingNetworkRequest() Constructor for QgsBlockingNetworkRequest
Methods
Aborts the network request immediately.
Returns the authentication config id which will be used during the request.
Performs a "delete" operation on the specified
request
.Returns the error message string, after a
get()
,post()
,head()
orput()
request has been made.Performs a "get" operation on the specified
request
.Performs a "head" operation on the specified
request
.Performs a "post" operation on the specified
request
, using the givendata
.Performs a "put" operation on the specified
request
, using the givendata
.Returns the content of the network reply, after a
get()
,post()
,head()
orput()
request has been made.Sets the authentication config id which should be used during the request.
Signals
pyqtSignal(*types, name: str = ..., revision: int = ..., arguments: Sequence = ...) -> PYQT_SIGNAL
pyqtSignal(*types, name: str = ..., revision: int = ..., arguments: Sequence = ...) -> PYQT_SIGNAL
pyqtSignal(*types, name: str = ..., revision: int = ..., arguments: Sequence = ...) -> PYQT_SIGNAL
pyqtSignal(*types, name: str = ..., revision: int = ..., arguments: Sequence = ...) -> PYQT_SIGNAL
Attributes
- class ErrorCode¶
Bases:
int
- NetworkError = 1¶
- NoError = 0¶
- ServerExceptionError = 3¶
- TimeoutError = 2¶
- abort(self)¶
Aborts the network request immediately.
- authCfg(self) str ¶
Returns the authentication config id which will be used during the request.
See also
- Return type:
str
- childEvent(self, QChildEvent)¶
- connectNotify(self, QMetaMethod)¶
- customEvent(self, QEvent)¶
- deleteResource(self, request: QNetworkRequest, feedback: QgsFeedback = None) QgsBlockingNetworkRequest.ErrorCode ¶
Performs a “delete” operation on the specified
request
.If an
authCfg()
has been set, then any authentication configuration required will automatically be applied torequest
. There is no need to manually apply the authentication to the request prior to calling this method.The optional
feedback
argument can be used to abort ongoing requests.The method will return NoError if the get operation was successful. The contents of the reply can be retrieved by calling
reply()
.If an error was encountered then a specific ErrorCode will be returned, and a detailed error message can be retrieved by calling
errorMessage()
.New in version 3.18.
- Parameters:
request (QNetworkRequest) –
feedback (
QgsFeedback
= None) –
- Return type:
- disconnectNotify(self, QMetaMethod)¶
- downloadFinished¶
pyqtSignal(*types, name: str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL
types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.
- Parameters:
name (str = ...) –
revision (int = ...) –
arguments (Sequence = ...) –
- Return type:
PYQT_SIGNAL
- downloadProgress¶
pyqtSignal(*types, name: str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL
types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.
- Parameters:
name (str = ...) –
revision (int = ...) –
arguments (Sequence = ...) –
- Return type:
PYQT_SIGNAL
- errorMessage(self) str ¶
Returns the error message string, after a
get()
,post()
,head()
orput()
request has been made.- Return type:
str
- finished¶
pyqtSignal(*types, name: str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL
types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.
- Parameters:
name (str = ...) –
revision (int = ...) –
arguments (Sequence = ...) –
- Return type:
PYQT_SIGNAL
- get(self, request: QNetworkRequest, forceRefresh: bool = False, feedback: QgsFeedback = None) QgsBlockingNetworkRequest.ErrorCode ¶
Performs a “get” operation on the specified
request
.If
forceRefresh
isFalse
then previously cached replies may be used for the request. If it is set toTrue
then a new query is always performed.If an
authCfg()
has been set, then any authentication configuration required will automatically be applied torequest
. There is no need to manually apply the authentication to the request prior to calling this method.The optional
feedback
argument can be used to abort ongoing requests.The method will return NoError if the get operation was successful. The contents of the reply can be retrieved by calling
reply()
.If an error was encountered then a specific ErrorCode will be returned, and a detailed error message can be retrieved by calling
errorMessage()
.See also
- Parameters:
request (QNetworkRequest) –
forceRefresh (bool = False) –
feedback (
QgsFeedback
= None) –
- Return type:
- head(self, request: QNetworkRequest, forceRefresh: bool = False, feedback: QgsFeedback = None) QgsBlockingNetworkRequest.ErrorCode ¶
Performs a “head” operation on the specified
request
.If
forceRefresh
isFalse
then previously cached replies may be used for the request. If it is set toTrue
then a new query is always performed.If an
authCfg()
has been set, then any authentication configuration required will automatically be applied torequest
. There is no need to manually apply the authentication to the request prior to calling this method.The optional
feedback
argument can be used to abort ongoing requests.The method will return NoError if the get operation was successful. The contents of the reply can be retrieved by calling
reply()
.If an error was encountered then a specific ErrorCode will be returned, and a detailed error message can be retrieved by calling
errorMessage()
.New in version 3.18.
- Parameters:
request (QNetworkRequest) –
forceRefresh (bool = False) –
feedback (
QgsFeedback
= None) –
- Return type:
- isSignalConnected(self, QMetaMethod) bool ¶
- post(self, request: QNetworkRequest, data: QIODevice, forceRefresh: bool = False, feedback: QgsFeedback = None) QgsBlockingNetworkRequest.ErrorCode ¶
Performs a “post” operation on the specified
request
, using the givendata
.If
forceRefresh
isFalse
then previously cached replies may be used for the request. If it is set toTrue
then a new query is always performed.If an
authCfg()
has been set, then any authentication configuration required will automatically be applied torequest
. There is no need to manually apply the authentication to the request prior to calling this method.The optional
feedback
argument can be used to abort ongoing requests.The method will return NoError if the get operation was successful. The contents of the reply can be retrieved by calling
reply()
.If an error was encountered then a specific ErrorCode will be returned, and a detailed error message can be retrieved by calling
errorMessage()
.See also
New in version 3.22.
post(self, request: QNetworkRequest, data: Union[QByteArray, bytes, bytearray], forceRefresh: bool = False, feedback:
QgsFeedback
= None) -> QgsBlockingNetworkRequest.ErrorCode This is an overloaded function.Performs a “post” operation on the specified
request
, using the givendata
.- Parameters:
request (QNetworkRequest) –
data (QIODevice) –
forceRefresh (bool = False) –
feedback (
QgsFeedback
= None) –
- Return type:
- put(self, request: QNetworkRequest, data: QIODevice, feedback: QgsFeedback = None) QgsBlockingNetworkRequest.ErrorCode ¶
Performs a “put” operation on the specified
request
, using the givendata
.If an
authCfg()
has been set, then any authentication configuration required will automatically be applied torequest
. There is no need to manually apply the authentication to the request prior to calling this method.The optional
feedback
argument can be used to abort ongoing requests.The method will return NoError if the get operation was successful. The contents of the reply can be retrieved by calling
reply()
.If an error was encountered then a specific ErrorCode will be returned, and a detailed error message can be retrieved by calling
errorMessage()
.New in version 3.22.
put(self, request: QNetworkRequest, data: Union[QByteArray, bytes, bytearray], feedback:
QgsFeedback
= None) -> QgsBlockingNetworkRequest.ErrorCode This is an overloaded function.Performs a “put” operation on the specified
request
, using the givendata
.New in version 3.18.
- Parameters:
request (QNetworkRequest) –
data (QIODevice) –
feedback (
QgsFeedback
= None) –
- Return type:
- receivers(self, PYQT_SIGNAL) int ¶
- reply(self) QgsNetworkReplyContent ¶
Returns the content of the network reply, after a
get()
,post()
,head()
orput()
request has been made.- Return type:
- sender(self) QObject ¶
- senderSignalIndex(self) int ¶
- setAuthCfg(self, authCfg: str)¶
Sets the authentication config id which should be used during the request.
See also
- Parameters:
authCfg (str) –
- timerEvent(self, QTimerEvent)¶
- uploadProgress¶
pyqtSignal(*types, name: str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL
types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.
- Parameters:
name (str = ...) –
revision (int = ...) –
arguments (Sequence = ...) –
- Return type:
PYQT_SIGNAL