Class: QgsBlockingNetworkRequest

class qgis.core.QgsBlockingNetworkRequest

Bases: PyQt5.QtCore.QObject

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.

QgsBlockingNetworkRequest() Constructor for QgsBlockingNetworkRequest

Methods

abort

Aborts the network request immediately.

authCfg

Returns the authentication config id which will be used during the request.

childEvent

connectNotify

customEvent

deleteResource

Performs a "delete" operation on the specified request.

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.

head

Performs a "head" operation on the specified request.

isSignalConnected

post

Performs a "post" operation on the specified request, using the given data.

put

Performs a "put" 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

pyqtSignal(*types, name: str = ..., revision: int = ..., arguments: Sequence = ...) -> PYQT_SIGNAL

downloadProgress

pyqtSignal(*types, name: str = ..., revision: int = ..., arguments: Sequence = ...) -> PYQT_SIGNAL

finished

pyqtSignal(*types, name: str = ..., revision: int = ..., arguments: Sequence = ...) -> PYQT_SIGNAL

uploadProgress

pyqtSignal(*types, name: str = ..., revision: int = ..., arguments: Sequence = ...) -> PYQT_SIGNAL

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()

Return type:

str

childEvent(self, QChildEvent)
connectNotify(self, QMetaMethod)
customEvent(self, QEvent)
deleteResource(self, request: QNetworkRequest, feedback: QgsFeedback = None) QgsBlockingNetworkRequest.ErrorCode

Performs a “delete” operation on the specified request.

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().

New in version 3.18.

Parameters:
  • request (QNetworkRequest) –

  • feedback (QgsFeedback = None) –

Return type:

QgsBlockingNetworkRequest.ErrorCode

disconnectNotify(self, QMetaMethod)
downloadFinished

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.

Parameters:
  • name (str = ...) –

  • revision (int = ...) –

  • arguments (Sequence = ...) –

Return type:

PYQT_SIGNAL

downloadProgress

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.

Parameters:
  • name (str = ...) –

  • revision (int = ...) –

  • arguments (Sequence = ...) –

Return type:

PYQT_SIGNAL

errorMessage(self) str

Returns the error message string, after a get() or post() request has been made.

Return type:

str

finished

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.

Parameters:
  • name (str = ...) –

  • revision (int = ...) –

  • arguments (Sequence = ...) –

Return type:

PYQT_SIGNAL

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()

Parameters:
  • request (QNetworkRequest) –

  • forceRefresh (bool = False) –

  • feedback (QgsFeedback = None) –

Return type:

QgsBlockingNetworkRequest.ErrorCode

head(self, request: QNetworkRequest, forceRefresh: bool = False, feedback: QgsFeedback = None) QgsBlockingNetworkRequest.ErrorCode

Performs a “head” 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().

New in version 3.18.

Parameters:
  • request (QNetworkRequest) –

  • forceRefresh (bool = False) –

  • feedback (QgsFeedback = None) –

Return type:

QgsBlockingNetworkRequest.ErrorCode

isSignalConnected(self, QMetaMethod) bool
post(self, request: QNetworkRequest, data: QIODevice, 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()

New in version 3.22.

post(self, request: QNetworkRequest, data: Union[QByteArray, bytes, bytearray], forceRefresh: bool = False, feedback: QgsFeedback = None) -> QgsBlockingNetworkRequest.ErrorCode This is an overloaded function.

Performs a “post” operation on the specified request, using the given data.

Parameters:
  • request (QNetworkRequest) –

  • data (QIODevice) –

  • forceRefresh (bool = False) –

  • feedback (QgsFeedback = None) –

Return type:

QgsBlockingNetworkRequest.ErrorCode

put(self, request: QNetworkRequest, data: QIODevice, feedback: QgsFeedback = None) QgsBlockingNetworkRequest.ErrorCode

Performs a “put” operation on the specified request, using the given data.

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().

New in version 3.22.

put(self, request: QNetworkRequest, data: Union[QByteArray, bytes, bytearray], feedback: QgsFeedback = None) -> QgsBlockingNetworkRequest.ErrorCode This is an overloaded function.

Performs a “put” operation on the specified request, using the given data.

New in version 3.18.

Parameters:
  • request (QNetworkRequest) –

  • data (QIODevice) –

  • feedback (QgsFeedback = None) –

Return type:

QgsBlockingNetworkRequest.ErrorCode

receivers(self, PYQT_SIGNAL) int
reply(self) QgsNetworkReplyContent

Returns the content of the network reply, after a get() or post() request has been made.

Return type:

QgsNetworkReplyContent

sender(self) QObject
senderSignalIndex(self) int
setAuthCfg(self, authCfg: str)

Sets the authentication config id which should be used during the request.

See also

authCfg()

Parameters:

authCfg (str) –

timerEvent(self, QTimerEvent)
uploadProgress

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.

Parameters:
  • name (str = ...) –

  • revision (int = ...) –

  • arguments (Sequence = ...) –

Return type:

PYQT_SIGNAL