Subgroup: Network

Class: QgsNetworkAccessManager

class qgis.core.QgsNetworkAccessManager

Bases: PyQt5.QtNetwork.QNetworkAccessManager

network access manager for QGIS

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.

New in version 1.5: Methods

cacheLoadControlFromName Gets QNetworkRequest.CacheLoadControl from name
cacheLoadControlName Gets name for QNetworkRequest.CacheLoadControl
childEvent
connectNotify
createRequest
customEvent
disconnectNotify
excludeList retrieve exclude list (urls shouldn’t use the fallback proxy)
fallbackProxy retrieve fall back proxy (for urls that no factory returned proxies for)
insertProxyFactory insert a factory into the proxy factories list
instance Returns a pointer to the active QgsNetworkAccessManager for the current thread.
isSignalConnected
proxyFactories retrieve proxy factory list
receivers
removeProxyFactory remove a factory from the proxy factories list
sender
senderSignalIndex
setFallbackProxyAndExcludes Sets fallback proxy and URL that shouldn’t use it.
setupDefaultProxyAndCache Setup the QgsNetworkAccessManager (NAM) according to the user’s settings.
supportedSchemesImplementation
timerEvent
useSystemProxy Returns whether the system proxy should be used

Signals

requestAboutToBeCreated requestAboutToBeCreated(self, QNetworkAccessManager.Operation, QNetworkRequest, QIODevice) [signal]
requestCreated requestCreated(self, QNetworkReply) [signal]
requestTimedOut requestTimedOut(self, QNetworkReply) [signal]

Attributes

cacheLoadControlFromName(name: str) → QNetworkRequest.CacheLoadControl

Gets QNetworkRequest.CacheLoadControl from name

cacheLoadControlName(control: QNetworkRequest.CacheLoadControl) → str

Gets name for QNetworkRequest.CacheLoadControl

childEvent()
connectNotify()
createRequest(self, op: QNetworkAccessManager.Operation, req: QNetworkRequest, outgoingData: QIODevice = None) → QNetworkReply
customEvent()
disconnectNotify()
excludeList(self) → List[str]

retrieve exclude list (urls shouldn’t use the fallback proxy)

fallbackProxy(self) → QNetworkProxy

retrieve fall back proxy (for urls that no factory returned proxies for)

insertProxyFactory(self, factory: QNetworkProxyFactory)

insert a factory into the proxy factories list

instance(connectionType: Qt.ConnectionType = Qt.BlockingQueuedConnection) → QgsNetworkAccessManager

Returns a pointer to the active QgsNetworkAccessManager for the current thread.

With the connectionType parameter 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 – In most cases the default of using a Qt.BlockingQueuedConnection is 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.
isSignalConnected()
proxyFactories(self) → object

retrieve proxy factory list

receivers()
removeProxyFactory(self, factory: QNetworkProxyFactory)

remove a factory from the proxy factories list

requestAboutToBeCreated

requestAboutToBeCreated(self, QNetworkAccessManager.Operation, QNetworkRequest, QIODevice) [signal]

requestCreated

requestCreated(self, QNetworkReply) [signal]

requestTimedOut

requestTimedOut(self, QNetworkReply) [signal]

sender()
senderSignalIndex()
setFallbackProxyAndExcludes(self, proxy: QNetworkProxy, excludes: Iterable[str])

Sets fallback proxy and URL that shouldn’t use it.

setupDefaultProxyAndCache(self, connectionType: Qt.ConnectionType = Qt.BlockingQueuedConnection)

Setup the QgsNetworkAccessManager (NAM) according to the user’s settings. The connectionType sets 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.

supportedSchemesImplementation()
timerEvent()
useSystemProxy(self) → bool

Returns whether the system proxy should be used