Class: QgsBlockingNetworkRequest¶
-
class
qgis.core.
QgsBlockingNetworkRequest
¶ Bases:
PyQt5.QtCore.QObject
Constructor for QgsBlockingNetworkRequest
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 a QgsNetworkReplyContent container, which is safe and cheap to copy and pass between threads without issue.
New in version 3.6: Enums
Methods
Aborts the network request immediately.
Returns the authentication config id which will be used during the request.
Returns the error message string, after a get() or post() request has been made.
Performs a “get” operation on the specified
request
.Performs a “post” operation on the specified
request
, using the givendata
.Returns the content of the network reply, after a get() or post() request has been made.
Sets the authentication config id which should be used during the request.
Signals
Emitted once a request has finished downloading.
Emitted when when data arrives during a request.
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
-
childEvent
()¶
-
connectNotify
()¶
-
customEvent
()¶
-
disconnectNotify
()¶
-
downloadFinished
¶ Emitted once a request has finished downloading. [signal]
-
downloadProgress
¶ Emitted when when data arrives during a request. [signal]
-
errorMessage
(self) → str¶ Returns the error message string, after a get() or post() request has been made.
-
get
(self, request: QNetworkRequest, forceRefresh: bool = False, feedback: QgsFeedback = None) → QgsBlockingNetworkRequest.ErrorCode¶ Performs a “get” operation on the specified
request
.If
forceRefresh
is false then previously cached replies may be used for the request. If it is set to true then a new query is always performed.If an authCfg() has been set, then any authentication configuration required will automatically be applied to
request
. 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
-
isSignalConnected
()¶
-
post
(self, request: QNetworkRequest, data: Union[QByteArray, bytes, bytearray], forceRefresh: bool = False, feedback: QgsFeedback = None) → QgsBlockingNetworkRequest.ErrorCode¶ Performs a “post” operation on the specified
request
, using the givendata
.If
forceRefresh
is false then previously cached replies may be used for the request. If it is set to true then a new query is always performed.If an authCfg() has been set, then any authentication configuration required will automatically be applied to
request
. 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
-
receivers
()¶
-
reply
(self) → QgsNetworkReplyContent¶ Returns the content of the network reply, after a get() or post() request has been made.
-
sender
()¶
-
senderSignalIndex
()¶
-
setAuthCfg
(self, authCfg: str)¶ Sets the authentication config id which should be used during the request.
See also
-
timerEvent
()¶
-
class