Class: QgsNetworkAccessManager¶
QNetworkAccessManager with additional QGIS specific logic.
This class implements the QGIS network access manager. It’s a singleton that can be used across QGIS.
Plugins can insert proxy factories and thereby redirect requests to individual proxies.
If no proxy factories are there or none returns a proxy for an URL a fallback proxy can be set. There’s also a exclude list that defines URLs that the fallback proxy should not be used for, then no proxy will be used.
Class Hierarchy¶
Base classes¶
- class qgis.core.QgsNetworkAccessManager[source]¶
Bases:
QNetworkAccessManager- abortAuthBrowser(self)[source]¶
Abort any outstanding external browser login request.
Note
Background threads will listen to aborted browser request signals from the network manager on the main thread.
Added in version 3.20.
- signal authBrowserAborted[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.
- static blockingGet(request: QNetworkRequest, authCfg: str | None = '', forceRefresh: bool = False, feedback: QgsFeedback | None = None, flags: Qgis.NetworkRequestFlags | Qgis.NetworkRequestFlag = Qgis.NetworkRequestFlags()) QgsNetworkReplyContent[source]¶
Posts a GET request to obtain the contents of the target request and returns a new
QgsNetworkReplyContentobject for reading. The current thread will be blocked until the request is returned.This method is safe to call in either the main thread or a worker thread.
If
forceRefreshisFalsethen previously cached replies may be used for the request. If it is set toTruethen a new query is always performed.If an
authCfghas been specified, then that 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 contents of the reply will be returned after the request is completed or an error occurs.
The
flagsargument was added in QGIS 4.0.See also
Added in version 3.6.
- Parameters:
request (QNetworkRequest)
authCfg (Optional[str] = '')
forceRefresh (bool = False)
feedback (Optional[QgsFeedback] = None)
flags (Union[Qgis.NetworkRequestFlags, Qgis.NetworkRequestFlag] = Qgis.NetworkRequestFlags())
- Return type:
- static blockingPost(request: QNetworkRequest, data: QByteArray | bytes | bytearray, authCfg: str | None = '', forceRefresh: bool = False, feedback: QgsFeedback | None = None, flags: Qgis.NetworkRequestFlags | Qgis.NetworkRequestFlag = Qgis.NetworkRequestFlags()) QgsNetworkReplyContent[source]¶
Posts a POST request to obtain the contents of the target
request, using the givendata, and returns a newQgsNetworkReplyContentobject for reading. The current thread will be blocked until the request is returned.This method is safe to call in either the main thread or a worker thread.
If
forceRefreshisFalsethen previously cached replies may be used for the request. If it is set toTruethen a new query is always performed.If an
authCfghas been specified, then that 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 contents of the reply will be returned after the request is completed or an error occurs.
The
flagsargument was added in QGIS 4.0.See also
Added in version 3.6.
- Parameters:
request (QNetworkRequest)
data (Union[QByteArray, bytes, bytearray])
authCfg (Optional[str] = '')
forceRefresh (bool = False)
feedback (Optional[QgsFeedback] = None)
flags (Union[Qgis.NetworkRequestFlags, Qgis.NetworkRequestFlag] = Qgis.NetworkRequestFlags())
- Return type:
- static cacheLoadControlFromName(name: str | None) QNetworkRequest.CacheLoadControl[source]¶
Returns QNetworkRequest.CacheLoadControl from a
name.See also
- Parameters:
name (Optional[str])
- Return type:
QNetworkRequest.CacheLoadControl
- static cacheLoadControlName(control: QNetworkRequest.CacheLoadControl) str[source]¶
Returns the name for QNetworkRequest.CacheLoadControl.
See also
- Parameters:
control (QNetworkRequest.CacheLoadControl)
- Return type:
str
- signal cookiesChanged[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.
- excludeList(self) List[str][source]¶
Returns the proxy exclude list.
This list consists of the beginning of URL strings which will not use the fallback proxy.
See also
See also
See also
- Return type:
List[str]
- fallbackProxy(self) QNetworkProxy¶
Returns the fallback proxy used by the manager.
The fallback proxy is used for URLs which no other proxy factory returned proxies for.
See also
See also
- Return type:
QNetworkProxy
- insertProxyFactory(self, factory: QNetworkProxyFactory | None)[source]¶
Inserts a
factoryinto the proxy factories list.Ownership of
factoryis transferred to the manager.See also
See also
- Parameters:
factory (Optional[QNetworkProxyFactory])
- static instance(connectionType: Qt.ConnectionType = Qt.BlockingQueuedConnection) QgsNetworkAccessManager | None[source]¶
Returns a pointer to the active
QgsNetworkAccessManagerfor the current thread.With the
connectionTypeparameter it is possible to setup the default connection type that is used to handle signals that might require user interaction and therefore need to be handled on the main thread. See in-depth discussion below.- Parameters:
connectionType (Qt.ConnectionType = Qt.BlockingQueuedConnection) – In most cases the default of using a
Qt.BlockingQueuedConnectionis ok, to make a background thread wait for the main thread to answer such a request is fine and anything else is dangerous. However, in case the request was started on the main thread, one should execute a local event loop in a helper thread and freeze the main thread for the duration of the download. In this case, if an authentication request is sent from the background thread network access manager, the background thread should be blocked, the main thread be woken up,processEvents()executed once, the main thread frozen again and the background thread continued.- Return type:
Optional[QgsNetworkAccessManager]
- noProxyList(self) List[str][source]¶
Returns the no proxy list.
This list consists of the beginning of URL strings which will not use any proxy at all
See also
See also
See also
- Return type:
List[str]
- preprocessRequest(self, req: QNetworkRequest | None)[source]¶
Preprocesses request
- Parameters:
req (Optional[QNetworkRequest]) – the request to preprocess
Added in version 3.22.
- proxyFactories(self) List[QNetworkProxyFactory]¶
Returns a list of proxy factories used by the manager.
See also
See also
- Return type:
List[QNetworkProxyFactory]
- static removeAdvancedRequestPreprocessor(id: str | None)[source]¶
Removes an advanced request pre-processor function with matching
id.The
idmust correspond to a pre-processor previously added via a call tosetAdvancedRequestPreprocessor().Returns
Trueif processor existed and was removed.See also
Added in version 3.44.
- Parameters:
id (Optional[str])
- removeProxyFactory(self, factory: QNetworkProxyFactory | None)[source]¶
Removes a
factoryfrom the proxy factories list.See also
See also
- Parameters:
factory (Optional[QNetworkProxyFactory])
- static removeReplyPreprocessor(id: str | None)[source]¶
Removes the custom reply pre-processor function with matching
id.The
idmust correspond to a pre-processor previously added via a call tosetReplyPreprocessor().Returns
Trueif processor existed and was removed.See also
Added in version 3.26.
- Parameters:
id (Optional[str])
- static removeRequestPreprocessor(id: str | None)[source]¶
Removes the custom request pre-processor function with matching
id.The
idmust correspond to a pre-processor previously added via a call tosetRequestPreprocessor().Returns
Trueif processor existed and was removed.See also
Added in version 3.22.
- Parameters:
id (Optional[str])
- signal requestAboutToBeCreated[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.
- requestAuthCloseBrowser(self)[source]¶
Forwards an external browser login closure request to the authentication handler.
Note
If called by a background thread, the request will be forwarded to the network manager on the main thread.
Added in version 3.20.
- signal requestAuthDetailsAdded[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.
- requestAuthOpenBrowser(self, url: QUrl)[source]¶
Forwards an external browser login
urlopening request to the authentication handler.Note
If called by a background thread, the request will be forwarded to the network manager on the main thread.
Added in version 3.20.
- Parameters:
url (QUrl)
- signal requestCreated[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 requestEncounteredSslErrors[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 requestRequiresAuth[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 requestTimedOut[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.
- static setAdvancedRequestPreprocessor(a0: Callable[..., None] | None) str[source]¶
Sets an advanced request pre-processor function, which allows manipulation of a network request before it is processed.
The
processorfunction takes the QNetworkRequest, network operation (a QNetworkAccessManager.Operation cast to an integer value), and request data as its arguments, and can mutate the request if necessary.It should return the desired operation (as a QNetworkAccessManager.Operation cast to an integer value) and request data as a tuple, transforming as desired.
- Return type:
str
- Returns:
An auto-generated string uniquely identifying the preprocessor, which can later be used to remove the preprocessor (via a call to
removeAdvancedRequestPreprocessor()).
See also
Added in version 3.44.
- Parameters:
a0 (Optional[Callable[..., None]])
- setFallbackProxyAndExcludes(self, proxy: QNetworkProxy, excludes: Iterable[str | None], noProxyURLs: Iterable[str | None])[source]¶
Sets the fallback
proxyand URLs which shouldn’t use it.The fallback proxy is used for URLs which no other proxy factory returned proxies for. The
excludeslist specifies the beginning of URL strings which will not use this fallback proxy. ThenoProxyURLslist specifies the beginning of URL strings which will not use any proxy at allSee also
See also
See also
- Parameters:
proxy (QNetworkProxy)
excludes (Iterable[Optional[str]])
noProxyURLs (Iterable[Optional[str]])
- static setReplyPreprocessor(a0: Callable[..., None] | None) str[source]¶
Sets a reply pre-processor function, which allows manipulation of QNetworkReply objects after they are created (but before they are fetched).
The
processorfunction takes a QNetworkRequest request and a QNetworkReply as arguments, and can connect to QNetworkReply signals directly as desired.- Return type:
str
- Returns:
An auto-generated string uniquely identifying the preprocessor, which can later be used to remove the preprocessor (via a call to
removeReplyPreprocessor()).
See also
Added in version 3.26.
- Parameters:
a0 (Optional[Callable[..., None]])
- static setRequestPreprocessor(a0: Callable[..., None] | None) str[source]¶
Sets a request pre-processor function, which allows manipulation of a network request before it is processed.
The
processorfunction takes the QNetworkRequest as its argument, and can mutate the request if necessary.- Return type:
str
- Returns:
An auto-generated string uniquely identifying the preprocessor, which can later be used to remove the preprocessor (via a call to
removeRequestPreprocessor()).
See also
Added in version 3.22.
- Parameters:
a0 (Optional[Callable[..., None]])
- static setTimeout(time: int)[source]¶
Sets the maximum timeout
timefor network requests, in milliseconds. If set to 0, no timeout is set.See also
Added in version 3.6.
- Parameters:
time (int)
- setupDefaultProxyAndCache(self, connectionType: Qt.ConnectionType = Qt.BlockingQueuedConnection)[source]¶
Setup the
QgsNetworkAccessManager(NAM) according to the user’s settings. TheconnectionTypesets up the default connection type that is used to handle signals that might require user interaction and therefore need to be handled on the main thread. See in-depth discussion in the documentation for the constructor of this class.- Parameters:
connectionType (Qt.ConnectionType = Qt.BlockingQueuedConnection)