Class: 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.
Added in version 3.6.
Class Hierarchy¶
Base classes¶
- class qgis.core.QgsBlockingNetworkRequest[source]¶
Bases:
QObject- __init__(flags: Qgis.NetworkRequestFlags | Qgis.NetworkRequestFlag = Qgis.NetworkRequestFlags())
Constructor for QgsBlockingNetworkRequest.
The
flagsargument was added in QGIS 4.0- Parameters:
flags (Union[Qgis.NetworkRequestFlags, Qgis.NetworkRequestFlag] = Qgis.NetworkRequestFlags())
- class ErrorCode¶
Bases:
int
- NetworkError = 1¶
- NoError = 0¶
- class RequestFlag(*values)¶
Bases:
IntEnumRequest flags
Added in version 3.40.
EmptyResponseIsValid: Do not generate an error if getting an empty response (e.g. HTTP 204)
- EmptyResponseIsValid = 1¶
- class RequestFlags¶
- class RequestFlags(f: QgsBlockingNetworkRequest.RequestFlags | QgsBlockingNetworkRequest.RequestFlag)
- class RequestFlags(a0: QgsBlockingNetworkRequest.RequestFlags)
Bases:
object
- ServerExceptionError = 3¶
- TimeoutError = 2¶
- authCfg(self) str[source]¶
Returns the authentication config id which will be used during the request.
See also
- Return type:
str
- deleteResource(self, request: QNetworkRequest, feedback: QgsFeedback | None = None) QgsBlockingNetworkRequest.ErrorCode[source]¶
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
feedbackargument 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().Added in version 3.18.
- Parameters:
request (QNetworkRequest)
feedback (Optional[QgsFeedback] = None)
- Return type:
- signal downloadFinished[source]¶
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.
- signal downloadProgress[source]¶
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.
- errorMessage(self) str[source]¶
Returns the error message string, after a
get(),post(),head()orput()request has been made.- Return type:
str
- signal finished[source]¶
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.
- flags(self) Qgis.NetworkRequestFlags[source]¶
Returns the network request flags.
Added in version 4.0.
- Return type:
- get(self, request: QNetworkRequest, forceRefresh: bool = False, feedback: QgsFeedback | None = None, requestFlags: QgsBlockingNetworkRequest.RequestFlags | QgsBlockingNetworkRequest.RequestFlag = QgsBlockingNetworkRequest.RequestFlags()) QgsBlockingNetworkRequest.ErrorCode[source]¶
Performs a “get” operation on the specified
request.If
forceRefreshisFalsethen previously cached replies may be used for the request. If it is set toTruethen 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
feedbackargument can be used to abort ongoing requests.The optional
requestFlagsargument can be used to modify the behavior (added in QGIS 3.40).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 (Optional[QgsFeedback] = None)
requestFlags (Union[QgsBlockingNetworkRequest.RequestFlags, QgsBlockingNetworkRequest.RequestFlag] = QgsBlockingNetworkRequest.RequestFlags())
- Return type:
- head(self, request: QNetworkRequest, forceRefresh: bool = False, feedback: QgsFeedback | None = None) QgsBlockingNetworkRequest.ErrorCode[source]¶
Performs a “head” operation on the specified
request.If
forceRefreshisFalsethen previously cached replies may be used for the request. If it is set toTruethen 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
feedbackargument 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().Added in version 3.18.
- Parameters:
request (QNetworkRequest)
forceRefresh (bool = False)
feedback (Optional[QgsFeedback] = None)
- Return type:
- post(self, request: QNetworkRequest, data: QIODevice | None, forceRefresh: bool = False, feedback: QgsFeedback | None = None) QgsBlockingNetworkRequest.ErrorCode[source]¶
Performs a “post” operation on the specified
request, using the givendata.If
forceRefreshisFalsethen previously cached replies may be used for the request. If it is set toTruethen 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
feedbackargument 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
Added in version 3.22.
post(self, request: QNetworkRequest, data: Union[QByteArray, bytes, bytearray], forceRefresh: bool = False, feedback: Optional[QgsFeedback] = None) -> QgsBlockingNetworkRequest.ErrorCode This is an overloaded function.
Performs a “post” operation on the specified
request, using the givendata.- Parameters:
request (QNetworkRequest)
data (Optional[QIODevice])
forceRefresh (bool = False)
feedback (Optional[QgsFeedback] = None)
- Return type:
- put(self, request: QNetworkRequest, data: QIODevice | None, feedback: QgsFeedback | None = None) QgsBlockingNetworkRequest.ErrorCode[source]¶
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
feedbackargument 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().Added in version 3.22.
put(self, request: QNetworkRequest, data: Union[QByteArray, bytes, bytearray], feedback: Optional[QgsFeedback] = None) -> QgsBlockingNetworkRequest.ErrorCode This is an overloaded function.
Performs a “put” operation on the specified
request, using the givendata.Added in version 3.18.
- Parameters:
request (QNetworkRequest)
data (Optional[QIODevice])
feedback (Optional[QgsFeedback] = None)
- Return type:
- reply(self) QgsNetworkReplyContent[source]¶
Returns the content of the network reply, after a
get(),post(),head()orput()request has been made.- Return type:
- setAuthCfg(self, authCfg: str | None)[source]¶
Sets the authentication config id which should be used during the request.
See also
- Parameters:
authCfg (Optional[str])
- signal uploadProgress[source]¶
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.