Skip to content

PythonQt.Qt.QNetworkProxy

QNetworkProxy

PythonQtInstanceWrapper object

Native bases: PythonQtInstanceWrapper

Supplemental documentation: Qt 5 reference:

Detailed Description

QNetworkProxy provides the method for configuring network layer proxy support to the Qt network classes. The currently supported classes are QAbstractSocket, QTcpSocket, QUdpSocket, QTcpServer and QNetworkAccessManager. The proxy support is designed to be as transparent as possible. This means that existing network-enabled applications that you have written should automatically support network proxy using the following code.

QNetworkProxy proxy;
proxy.setType(QNetworkProxy::Socks5Proxy);
proxy.setHostName("proxy.example.com");
proxy.setPort(1080);
proxy.setUser("username");
proxy.setPassword("password");
QNetworkProxy::setApplicationProxy(proxy);

An alternative to setting an application wide proxy is to specify the proxy for individual sockets using QAbstractSocket::setProxy() and QTcpServer::setProxy(). In this way, it is possible to disable the use of a proxy for specific sockets using the following code:

serverSocket->setProxy(QNetworkProxy::NoProxy);

Network proxy is not used if the address used in connectToHost(), bind() or listen() is equivalent to QHostAddress::LocalHost or QHostAddress::LocalHostIPv6.

Each type of proxy support has certain restrictions associated with it. You should read the ProxyType documentation carefully before selecting a proxy type to use.

Note: Changes made to currently connected sockets do not take effect. If you need to change a connected socket, you should reconnect it.

SOCKS5

The SOCKS5 support since Qt 4 is based on RFC 1928 and RFC 1929. The supported authentication methods are no authentication and username/password authentication. Both IPv4 and IPv6 are supported. Domain names are resolved through the SOCKS5 server if the QNetworkProxy::HostNameLookupCapability is enabled, otherwise they are resolved locally and the IP address is sent to the server. There are several things to remember when using SOCKS5 with QUdpSocket and QTcpServer:

With QUdpSocket, a call to bind() may fail with a timeout error. If a port number other than 0 is passed to bind(), it is not guaranteed that it is the specified port that will be used. Use localPort() and localAddress() to get the actual address and port number in use. Because proxied UDP goes through two UDP connections, it is more likely that packets will be dropped.

With QTcpServer a call to listen() may fail with a timeout error. If a port number other than 0 is passed to listen(), then it is not guaranteed that it is the specified port that will be used. Use serverPort() and serverAddress() to get the actual address and port used to listen for connections. SOCKS5 only supports one accepted connection per call to listen(), and each call is likely to result in a different serverPort() being used.

Source: https://doc.qt.io/archives/qt-5.15/qnetworkproxy.html

Complete member index

Every captured member retains its own identity. Identical captured declaration text is linked once; this does not establish native inheritance or interchangeable objects.

Member Kind Signature Summary
CachingCapability attribute Any (shared captured text)
Capabilities attribute type Convert a number or string to an integer, or return 0 if no arguments are given. (shared captured text)
Capability attribute type Convert a number or string to an integer, or return 0 if no arguments are given. (shared captured text)
DefaultProxy attribute Any (shared captured text)
FtpCachingProxy attribute Any (shared captured text)
HostNameLookupCapability attribute Any (shared captured text)
HttpCachingProxy attribute Any (shared captured text)
HttpProxy attribute Any (shared captured text)
ListeningCapability attribute Any (shared captured text)
NoProxy attribute Any (shared captured text)
ProxyType attribute type Convert a number or string to an integer, or return 0 if no arguments are given. (shared captured text)
Socks5Proxy attribute Any (shared captured text)
TunnelingCapability attribute Any (shared captured text)
UdpTunnelingCapability attribute Any (shared captured text)
__init__ function (self, *args: Any, **kwargs: Any) -> None Native constructor; consult class documentation for supported overloads. (shared captured text)
applicationProxy function (self) -> Any X.applicationProxy() -> PythonQt.QtNetwork.QNetworkProxy (shared captured text)
capabilities function (self) -> Any Returns the capabilities of this proxy server. (shared captured text)
className function (self, *args: Any, **kwargs: Any) -> Any Return the classname of the object (shared captured text)
delete function (self, *args: Any, **kwargs: Any) -> Any Deletes the C++ object (at your own risk, my friend!) (shared captured text)
hasRawHeader function (self, headerName: Any) -> bool X.hasRawHeader(headerName) -> bool (shared captured text)
header function (self, header: Any) -> Any X.header(header) -> object (shared captured text)
help function (self, *args: Any, **kwargs: Any) -> Any Shows the help of available methods for this class (shared captured text)
hostName function (self) -> str X.hostName() -> str (shared captured text)
inherits function (self, *args: Any, **kwargs: Any) -> Any Returns if the class inherits or is of given type name (shared captured text)
isCachingProxy function (self) -> bool X.isCachingProxy() -> bool (shared captured text)
isTransparentProxy function (self) -> bool X.isTransparentProxy() -> bool (shared captured text)
password function (self) -> str X.password() -> str (shared captured text)
port function (self) -> int X.port() -> int (shared captured text)
rawHeader function (self, headerName: Any) -> Any X.rawHeader(headerName) -> PythonQt.QtCore.QByteArray (shared captured text)
rawHeaderList function (self) -> Any Returns a list of all raw headers that are set in this network proxy. (shared captured text)
setApplicationProxy function (self, proxy: Any) -> None Sets the application level network proxying to be networkProxy. (shared captured text)
setCapabilities function (self, capab: Any) -> None Sets the capabilities of this proxy to capabilities. (shared captured text)
setHeader function (self, header: Any, value: Any) -> None X.setHeader(header, value) (shared captured text)
setHostName function (self, hostName: str) -> None Sets the host name of the proxy host to be hostName. (shared captured text)
setPassword function (self, password: str) -> None Sets the password for proxy authentication to be password. (shared captured text)
setPort function (self, port: int) -> None Sets the port of the proxy host to be port. (shared captured text)
setRawHeader function (self, headerName: Any, value: Any) -> None X.setRawHeader(headerName, value) (shared captured text)
setType function (self, type: Any) -> None Sets the proxy type for this instance to be type. (shared captured text)
setUser function (self, userName: str) -> None Sets the user name for proxy authentication to be user. (shared captured text)
swap function (self, other: Any) -> None Swaps this network proxy instance with other. (shared captured text)
type function (self) -> Any Returns the proxy type for this instance. (shared captured text)
user function (self) -> str X.user() -> str (shared captured text)