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¶
Enums
Request flags |
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 |
|
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 given data. |
|
Performs a "put" operation on the specified request, using the given data. |
|
Returns the content of the network reply, after a |
|
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. |
|
Emitted once a request has finished. |
|
Emitted when when data are sent during a request. |
Attributes
- class qgis.core.QgsBlockingNetworkRequest[source]¶
Bases:
QObject
- __init__()
Constructor for QgsBlockingNetworkRequest
- class ErrorCode¶
Bases:
int
- NetworkError = 1¶
- NoError = 0¶
- class RequestFlag(*values)¶
Bases:
IntEnum
Request 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
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()
.Added in version 3.18.
- Parameters:
request (QNetworkRequest)
feedback (Optional[QgsFeedback] = None)
- Return type:
- signal downloadFinished[source]¶
Emitted once a request has finished downloading.
Deprecated since version 3.40: Use the
finished()
signal instead.
- signal downloadProgress(bytesReceived: int, bytesTotal: int)[source]¶
Emitted when when data arrives during a request.
- Parameters:
bytesReceived (int)
bytesTotal (int)
- errorMessage(self) str [source]¶
Returns the error message string, after a
get()
,post()
,head()
orput()
request has been made.- Return type:
str
- 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
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 optional
requestFlags
argument 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
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()
.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
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
Added in version 3.22.
- Parameters:
request (QNetworkRequest)
data (Optional[QIODevice])
forceRefresh (bool = False)
feedback (Optional[QgsFeedback] = None)
- Return type:
- post(self, request: QNetworkRequest, data: QByteArray | bytes | bytearray, forceRefresh: bool = False, feedback: QgsFeedback | None = None) QgsBlockingNetworkRequest.ErrorCode [source]
This is an overloaded function.
Performs a “post” operation on the specified
request
, using the givendata
.- Parameters:
request (QNetworkRequest)
data (Union[QByteArray, bytes, bytearray])
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
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()
.Added in version 3.22.
- Parameters:
request (QNetworkRequest)
data (Optional[QIODevice])
feedback (Optional[QgsFeedback] = None)
- Return type:
- put(self, request: QNetworkRequest, data: QByteArray | bytes | bytearray, feedback: QgsFeedback | None = None) QgsBlockingNetworkRequest.ErrorCode [source]
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 (Union[QByteArray, bytes, bytearray])
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: