Class: QgsNetworkContentFetcher

HTTP network content fetcher.

A simple method for fetching remote HTTP content and converting the content to standard formats.

URL redirects are automatically handled.

Class Hierarchy

Inheritance diagram of qgis.core.QgsNetworkContentFetcher

Base classes

QObject

Methods

cancel

Cancels any ongoing request.

contentAsString

Returns the fetched content as a string

contentDispositionFilename

Returns the associated filename from the reply's content disposition header, if present.

fetchContent

Fetches content from a remote URL and handles redirects.

reply

Returns a reference to the network reply

wasCanceled

Returns True if the fetching was canceled.

Signals

downloadProgress

Emitted when data is received.

errorOccurred

Emitted when an error with code error occurred while processing the request errorMsg is a textual description of the error

finished

Emitted when content has loaded

class qgis.core.QgsNetworkContentFetcher[source]

Bases: QObject

cancel(self)[source]

Cancels any ongoing request.

Added in version 3.2.

contentAsString(self) str[source]

Returns the fetched content as a string

Return type:

str

Returns:

string containing network content

contentDispositionFilename(self) str[source]

Returns the associated filename from the reply’s content disposition header, if present.

Added in version 3.28.

Return type:

str

signal downloadProgress(bytesReceived: int, bytesTotal: int)[source]

Emitted when data is received.

Added in version 3.2.

Parameters:
  • bytesReceived (int)

  • bytesTotal (int)

signal errorOccurred(code: QNetworkReply.NetworkError, errorMsg: str)[source]

Emitted when an error with code error occurred while processing the request errorMsg is a textual description of the error

Added in version 3.22.

Parameters:
  • code (QNetworkReply.NetworkError)

  • errorMsg (str)

fetchContent(self, url: QUrl, authcfg: str | None = '')[source]

Fetches content from a remote URL and handles redirects. The finished() signal will be emitted when content has been fetched.

Parameters:
  • url (QUrl) – URL to fetch

  • authcfg (Optional[str] = '') – optional authentication configuration

fetchContent(self, request: QNetworkRequest, authcfg: str | None = '')[source]

Fetches content using a network request and handles redirects. The finished() signal will be emitted when content has been fetched.

Optionally, authentication configuration can be set via the authcfg argument.

Added in version 3.2.

Parameters:
  • request (QNetworkRequest)

  • authcfg (Optional[str] = '')

signal finished[source]

Emitted when content has loaded

reply(self) QNetworkReply | None[source]

Returns a reference to the network reply

Return type:

Optional[QNetworkReply]

Returns:

QNetworkReply for fetched URL content

wasCanceled(self) bool[source]

Returns True if the fetching was canceled.

Added in version 3.10.

Return type:

bool