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: Enums
Methods
Posts a GET request to obtain the contents of the target request and returns a new QgsNetworkReplyContent object for reading.
Posts a POST request to obtain the contents of the target
request
, using the givendata
, and returns a new QgsNetworkReplyContent object for reading.Returns QNetworkRequest.CacheLoadControl from a
name
.Returns the name for QNetworkRequest.CacheLoadControl.
Returns the proxy exclude list.
Returns the fallback proxy used by the manager.
Inserts a
factory
into the proxy factories list.Returns a pointer to the active QgsNetworkAccessManager for the current thread.
Returns a list of proxy factories used by the manager.
Removes a
factory
from the proxy factories list.Sets the fallback
proxy
and URLs which shouldn’t use it.Sets the maximum timeout
time
for network requests, in milliseconds.Setup the QgsNetworkAccessManager (NAM) according to the user’s settings.
Returns the network timeout length, in milliseconds.
Returns whether the system proxy should be used.
Signals
Emitted when a network reply receives a progress report.
This signal is emitted whenever a pending network reply is finished.
Deprecated since version Use: the thread-safe requestAboutToBeCreated( QgsNetworkRequestParameters ) signal instead. [signal]
Emitted when network authentication details have been added to a request.
Deprecated since version Use: the thread-safe requestAboutToBeCreated( QgsNetworkRequestParameters ) signal instead. [signal]
Emitted when a network request encounters SSL
errors
.Emitted when a network request prompts an authentication request.
Emitted when a network request has timed out.
Attributes
-
blockingGet
(request: QNetworkRequest, authCfg: str = '', forceRefresh: bool = False, feedback: QgsFeedback = None) → QgsNetworkReplyContent¶ Posts a GET request to obtain the contents of the target request and returns a new QgsNetworkReplyContent object 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
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 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
feedback
argument can be used to abort ongoing requests.The contents of the reply will be returned after the request is completed or an error occurs.
See also
New in version 3.6.
-
blockingPost
(request: QNetworkRequest, data: Union[QByteArray, bytes, bytearray], authCfg: str = '', forceRefresh: bool = False, feedback: QgsFeedback = None) → QgsNetworkReplyContent¶ Posts a POST request to obtain the contents of the target
request
, using the givendata
, and returns a new QgsNetworkReplyContent object 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
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 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
feedback
argument can be used to abort ongoing requests.The contents of the reply will be returned after the request is completed or an error occurs.
See also
New in version 3.6.
-
cacheLoadControlFromName
(name: str) → QNetworkRequest.CacheLoadControl¶ Returns QNetworkRequest.CacheLoadControl from a
name
.See also
-
cacheLoadControlName
(control: QNetworkRequest.CacheLoadControl) → str¶ Returns the name for QNetworkRequest.CacheLoadControl.
See also
-
childEvent
()¶
-
connectNotify
()¶
-
createRequest
(self, op: QNetworkAccessManager.Operation, req: QNetworkRequest, outgoingData: QIODevice = None) → QNetworkReply¶
-
customEvent
()¶
-
disconnectNotify
()¶
-
downloadProgress
¶ Emitted when a network reply receives a progress report.
The
requestId
argument reflects the unique ID identifying the original request which the progress report relates to.The
bytesReceived
parameter indicates the number of bytes received, whilebytesTotal
indicates the total number of bytes expected to be downloaded. If the number of bytes to be downloaded is not known,bytesTotal
will be -1.This signal is propagated to the main thread QgsNetworkAccessManager instance, so it is necessary only to connect to the main thread’s signal in order to receive notifications about requests created in any thread.
New in version 3.6: [signal]
-
excludeList
(self) → List[str]¶ 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
-
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
-
finished
¶ This signal is emitted whenever a pending network reply is finished.
The
reply
parameter will contain a QgsNetworkReplyContent object, containing all the useful information relating to the reply, including headers and reply content.This signal is propagated to the main thread QgsNetworkAccessManager instance, so it is necessary only to connect to the main thread’s signal in order to receive notifications about requests created in any thread.
See also
See also
New in version 3.6: [signal]
-
insertProxyFactory
(self, factory: QNetworkProxyFactory)¶ Inserts a
factory
into the proxy factories list.Ownership of
factory
is transferred to the manager.See also
See also
-
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¶ Returns a list of proxy factories used by the manager.
See also
See also
-
receivers
()¶
-
removeProxyFactory
(self, factory: QNetworkProxyFactory)¶ Removes a
factory
from the proxy factories list.See also
See also
-
requestAboutToBeCreated
¶ Deprecated since version Use: the thread-safe requestAboutToBeCreated( QgsNetworkRequestParameters ) signal instead. [signal]
requestAboutToBeCreated(self, QgsNetworkRequestParameters) Emitted when a network request is about to be created.
This signal is propagated to the main thread QgsNetworkAccessManager instance, so it is necessary only to connect to the main thread’s signal in order to receive notifications about requests created in any thread.
See also
See also
New in version 3.6: [signal]
-
requestAuthDetailsAdded
¶ Emitted when network authentication details have been added to a request.
The
requestId
argument reflects the unique ID identifying the original request which the authentication relates to.This signal is always sent from the main thread QgsNetworkAccessManager instance, so it is necessary only to connect to the main thread’s signal in order to receive notifications about authentication requests from any thread.
This signal is for debugging and logging purposes only, and should not be used to respond to the requests. See QgsNetworkAuthenticationHandler for details on how to handle authentication requests.
See also
New in version 3.6: [signal]
-
requestCreated
¶ Deprecated since version Use: the thread-safe requestAboutToBeCreated( QgsNetworkRequestParameters ) signal instead. [signal]
-
requestEncounteredSslErrors
¶ Emitted when a network request encounters SSL
errors
.The
requestId
argument reflects the unique ID identifying the original request which the SSL error relates to.This signal is propagated to the main thread QgsNetworkAccessManager instance, so it is necessary only to connect to the main thread’s signal in order to receive notifications about SSL errors from any thread.
This signal is for debugging and logging purposes only, and cannot be used to respond to the errors. See QgsSslErrorHandler for details on how to handle SSL errors and potentially ignore them.
New in version 3.6: [signal]
-
requestRequiresAuth
¶ Emitted when a network request prompts an authentication request.
The
requestId
argument reflects the unique ID identifying the original request which the authentication relates to.This signal is propagated to the main thread QgsNetworkAccessManager instance, so it is necessary only to connect to the main thread’s signal in order to receive notifications about authentication requests from any thread.
This signal is for debugging and logging purposes only, and cannot be used to respond to the requests. See QgsNetworkAuthenticationHandler for details on how to handle authentication requests.
See also
New in version 3.6: [signal]
-
requestTimedOut
¶ Emitted when a network request has timed out.
This signal is propagated to the main thread QgsNetworkAccessManager instance, so it is necessary only to connect to the main thread’s signal in order to receive notifications about requests created in any thread.
See also
See also
New in version 3.6: [signal]
requestTimedOut(self, QNetworkReply) [signal]
-
sender
()¶
-
senderSignalIndex
()¶
-
setFallbackProxyAndExcludes
(self, proxy: QNetworkProxy, excludes: Iterable[str])¶ Sets the fallback
proxy
and URLs which shouldn’t use it.The fallback proxy is used for URLs which no other proxy factory returned proxies for. The
excludes
list specifies the beginning of URL strings which will not use this fallback proxy.See also
See also
-
setTimeout
(time: int)¶ Sets the maximum timeout
time
for network requests, in milliseconds.See also
New in version 3.6.
-
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
()¶
-
timeout
() → int¶ Returns the network timeout length, in milliseconds.
See also
New in version 3.6.
-
timerEvent
()¶
-
useSystemProxy
(self) → bool¶ Returns whether the system proxy should be used.
-