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 aQgsNetworkReplyContent
container, which is safe and cheap to copy and pass between threads without issue.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()
orpost()
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()
orpost()
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
- Return type
str
-
childEvent
(self, QChildEvent)¶
-
connectNotify
(self, QMetaMethod)¶
-
customEvent
(self, QEvent)¶
-
disconnectNotify
(self, QMetaMethod)¶
-
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()
orpost()
request has been made.- Return type
str
-
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
-
isSignalConnected
(self, QMetaMethod) → bool¶
-
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
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) –
data (Union[QByteArray) –
forceRefresh (bool = False) –
feedback (
QgsFeedback
= None) –
- Return type
-
receivers
(self, PYQT_SIGNAL) → int¶
-
reply
(self) → QgsNetworkReplyContent¶ Returns the content of the network reply, after a
get()
orpost()
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)¶
-
class