Skip to content

PythonQt.QtNetwork.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
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
FtpCachingProxy attribute Any
HostNameLookupCapability attribute Any
HttpCachingProxy attribute Any
HttpProxy attribute Any
ListeningCapability attribute Any
NoProxy attribute Any
ProxyType attribute type Convert a number or string to an integer, or return 0 if no arguments are given.
Socks5Proxy attribute Any
TunnelingCapability attribute Any
UdpTunnelingCapability attribute Any
__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
capabilities function (self) -> Any Returns the capabilities of this proxy server.
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
header function (self, header: Any) -> Any X.header(header) -> object
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
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
isTransparentProxy function (self) -> bool X.isTransparentProxy() -> bool
password function (self) -> str X.password() -> str
port function (self) -> int X.port() -> int
rawHeader function (self, headerName: Any) -> Any X.rawHeader(headerName) -> PythonQt.QtCore.QByteArray
rawHeaderList function (self) -> Any Returns a list of all raw headers that are set in this network proxy.
setApplicationProxy function (self, proxy: Any) -> None Sets the application level network proxying to be networkProxy.
setCapabilities function (self, capab: Any) -> None Sets the capabilities of this proxy to capabilities.
setHeader function (self, header: Any, value: Any) -> None X.setHeader(header, value)
setHostName function (self, hostName: str) -> None Sets the host name of the proxy host to be hostName.
setPassword function (self, password: str) -> None Sets the password for proxy authentication to be password.
setPort function (self, port: int) -> None Sets the port of the proxy host to be port.
setRawHeader function (self, headerName: Any, value: Any) -> None X.setRawHeader(headerName, value)
setType function (self, type: Any) -> None Sets the proxy type for this instance to be type.
setUser function (self, userName: str) -> None Sets the user name for proxy authentication to be user.
swap function (self, other: Any) -> None Swaps this network proxy instance with other.
type function (self) -> Any Returns the proxy type for this instance.
user function (self) -> str X.user() -> str