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: Methods

abort Aborts the network request immediately.
authCfg Returns the authentication config id which will be used during the request.
childEvent
connectNotify
customEvent
disconnectNotify
errorMessage Returns the error message string, after a get() or post() request has been made.
get Performs a “get” operation on the specified request.
isSignalConnected
post Performs a “post” operation on the specified request, using the given data.
receivers
reply Returns the content of the network reply, after a get() or post() request has been made.
sender
senderSignalIndex
setAuthCfg Sets the authentication config id which should be used during the request.
timerEvent

Signals

downloadFinished Emitted once a request has finished downloading.
downloadProgress Emitted when when data arrives during a request.

Attributes

NetworkError
NoError
ServerExceptionError
TimeoutError
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

setAuthCfg()

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

post()

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 given data.

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

get()

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

authCfg()

timerEvent()