PySide6.QtNetwork.QNetworkProxy¶
- class QNetworkProxy¶
- The - QNetworkProxyclass provides a network layer proxy. More…- Synopsis¶- Methods¶- def - __init__()
- def - capabilities()
- def - hasRawHeader()
- def - header()
- def - headers()
- def - hostName()
- def - isCachingProxy()
- def - __ne__()
- def - __eq__()
- def - password()
- def - port()
- def - rawHeader()
- def - rawHeaderList()
- def - setHeader()
- def - setHeaders()
- def - setHostName()
- def - setPassword()
- def - setPort()
- def - setRawHeader()
- def - setType()
- def - setUser()
- def - swap()
- def - type()
- def - user()
 - Static functions¶- Note - This documentation may contain snippets that were automatically translated from C++ to Python. We always welcome contributions to the snippet translation. If you see an issue with the translation, you can also let us know by creating a ticket on https:/bugreports.qt.io/projects/PYSIDE - Detailed Description¶- Warning - This section contains snippets that were automatically translated from C++ to Python and may contain errors. - QNetworkProxyprovides the method for configuring network layer proxy support to the Qt network classes. The currently supported classes are- QAbstractSocket,- QTcpSocket,- QUdpSocket,- QTcpServerand- 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.- proxy = QNetworkProxy() 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 - setProxy()and- 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- LocalHostor- LocalHostIPv6.- Each type of proxy support has certain restrictions associated with it. You should read the - ProxyTypedocumentation 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 - HostNameLookupCapabilityis 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- QUdpSocketand- 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 - QTcpServera 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.- See also - class ProxyType¶
- This enum describes the types of network proxying provided in Qt. - There are two types of proxies that Qt understands: transparent proxies and caching proxies. The first group consists of proxies that can handle any arbitrary data transfer, while the second can only handle specific requests. The caching proxies only make sense for the specific classes where they can be used. - Constant - Description - QNetworkProxy.ProxyType.NoProxy - No proxying is used - QNetworkProxy.ProxyType.DefaultProxy - Proxy is determined based on the application proxy set using - setApplicationProxy()- QNetworkProxy.ProxyType.Socks5Proxy - Socks5proxying is used- QNetworkProxy.ProxyType.HttpProxy - HTTP transparent proxying is used - QNetworkProxy.ProxyType.HttpCachingProxy - Proxying for HTTP requests only - QNetworkProxy.ProxyType.FtpCachingProxy - Proxying for FTP requests only - The table below lists different proxy types and their capabilities. Since each proxy type has different capabilities, it is important to understand them before choosing a proxy type. - Proxy type - Description - Default capabilities - SOCKS 5 - Generic proxy for any kind of connection. Supports TCP, UDP, binding to a port (incoming connections) and authentication. - TunnelingCapability,- ListeningCapability,- UdpTunnelingCapability,- HostNameLookupCapability- HTTP - Implemented using the “CONNECT” command, supports only outgoing TCP connections; supports authentication. - TunnelingCapability,- CachingCapability,- HostNameLookupCapability- Caching-only HTTP - Implemented using normal HTTP commands, it is useful only in the context of HTTP requests (see - QNetworkAccessManager)- Caching FTP - Implemented using an FTP proxy, it is useful only in the context of FTP requests (see - QNetworkAccessManager)- Also note that you shouldn’t set the application default proxy ( - setApplicationProxy()) to a proxy that doesn’t have the- TunnelingCapabilitycapability. If you do,- QTcpSocketwill not know how to open connections.- See also 
 - class Capability¶
- (inherits - enum.Flag) These flags indicate the capabilities that a given proxy server supports.- QNetworkProxysets different capabilities by default when the object is created (see- ProxyTypefor a list of the defaults). However, it is possible to change the capabilities after the object has been created with- setCapabilities().- The capabilities that - QNetworkProxysupports are:- Constant - Description - QNetworkProxy.Capability.TunnelingCapability - Ability to open transparent, tunneled TCP connections to a remote host. The proxy server relays the transmission verbatim from one side to the other and does no caching. - QNetworkProxy.Capability.ListeningCapability - Ability to create a listening socket and wait for an incoming TCP connection from a remote host. - QNetworkProxy.Capability.UdpTunnelingCapability - Ability to relay UDP datagrams via the proxy server to and from a remote host. - QNetworkProxy.Capability.CachingCapability - Ability to cache the contents of the transfer. This capability is specific to each protocol and proxy type. For example, HTTP proxies can cache the contents of web data transferred with “GET” commands. - QNetworkProxy.Capability.HostNameLookupCapability - Ability to connect to perform the lookup on a remote host name and connect to it, as opposed to requiring the application to perform the name lookup and request connection to IP addresses only. - QNetworkProxy.Capability.SctpTunnelingCapability - Ability to open transparent, tunneled SCTP connections to a remote host. - QNetworkProxy.Capability.SctpListeningCapability - Ability to create a listening socket and wait for an incoming SCTP connection from a remote host. 
 - __init__()¶
 - Constructs a - QNetworkProxywith- DefaultProxytype.- The proxy type is determined by - applicationProxy(), which defaults to- NoProxyor a system-wide proxy if one is configured.- See also - __init__(other)
- Parameters:
- other – - QNetworkProxy
 
 - Constructs a copy of - other.- __init__(type[, hostName=""[, port=0[, user=""[, password=""]]]])
- Parameters:
- type – - ProxyType
- hostName – str 
- port – int 
- user – str 
- password – str 
 
 
 - Constructs a - QNetworkProxywith- type,- hostName,- port,- userand- password.- The default capabilities for proxy type - typeare set automatically.- See also - static applicationProxy()¶
- Return type:
 
 - Returns the application level network proxying. - If a - QAbstractSocketor- QTcpSockethas the- DefaultProxytype, then the- QNetworkProxyreturned by this function is used.- capabilities()¶
- Return type:
- Combination of - Capability
 
 - Returns the capabilities of this proxy server. - See also - hasRawHeader(headerName)¶
- Parameters:
- headerName – - QByteArray
- Return type:
- bool 
 
 - Returns - trueif the raw header- headerNameis in use for this proxy. Returns- falseif the proxy is not of type- HttpProxyor- HttpCachingProxy.- See also - header(header)¶
- Parameters:
- header – - KnownHeaders
- Return type:
- object 
 
 - Returns the value of the known network header - headerif it is in use for this proxy. If it is not present, returns QVariant() (i.e., an invalid variant).- See also - headers()¶
- Return type:
 
 - Returns headers that are set in this network request. - If the proxy is not of type - HttpProxyor- HttpCachingProxy, default constructed- QHttpHeadersis returned.- See also - hostName()¶
- Return type:
- str 
 
 - Returns the host name of the proxy host. - See also - isCachingProxy()¶
- Return type:
- bool 
 
 - Returns - trueif this proxy supports the- CachingCapabilitycapability.- In Qt 4.4, the capability was tied to the proxy type, but since Qt 4.5 it is possible to remove the capability of caching from a proxy by calling - setCapabilities().- See also - isTransparentProxy()¶
- Return type:
- bool 
 
 - Returns - trueif this proxy supports transparent tunneling of TCP connections. This matches the- TunnelingCapabilitycapability.- In Qt 4.4, the capability was tied to the proxy type, but since Qt 4.5 it is possible to remove the capability of caching from a proxy by calling - setCapabilities().- See also - __ne__(other)¶
- Parameters:
- other – - QNetworkProxy
- Return type:
- bool 
 
 - Compares the value of this network proxy to - otherand returns- trueif they differ.- __eq__(other)¶
- Parameters:
- other – - QNetworkProxy
- Return type:
- bool 
 
 - Compares the value of this network proxy to - otherand returns- trueif they are equal (same proxy type, server as well as username and password)- password()¶
- Return type:
- str 
 
 - Returns the password used for authentication. - See also - port()¶
- Return type:
- int 
 
 - Returns the port of the proxy host. - See also - rawHeader(headerName)¶
- Parameters:
- headerName – - QByteArray
- Return type:
 
 - Returns the raw form of header - headerName. If no such header is present or the proxy is not of type- HttpProxyor- HttpCachingProxy, an empty QByteArray is returned, which may be indistinguishable from a header that is present but has no content (use- hasRawHeader()to find out if the header exists or not).- Raw headers can be set with - setRawHeader()or with- setHeader().- See also - rawHeaderList()¶
- Return type:
- .list of QByteArray 
 
 - Returns a list of all raw headers that are set in this network proxy. The list is in the order that the headers were set. - If the proxy is not of type - HttpProxyor- HttpCachingProxyan empty QList is returned.- See also - static setApplicationProxy(proxy)¶
- Parameters:
- proxy – - QNetworkProxy
 
 - Sets the application level network proxying to be - networkProxy.- If a - QAbstractSocketor- QTcpSockethas the- DefaultProxytype, then the- QNetworkProxyset with this function is used. If you want more flexibility in determining which proxy is used, use the- QNetworkProxyFactoryclass.- Setting a default proxy value with this function will override the application proxy factory set with - setApplicationProxyFactory, and disable the use of a system proxy.- setCapabilities(capab)¶
- Parameters:
- capab – Combination of - Capability
 
 - Sets the capabilities of this proxy to - capabilities.- See also - setHeader(header, value)¶
- Parameters:
- header – - KnownHeaders
- value – object 
 
 
 - Sets the value of the known header - headerto be- value, overriding any previously set headers. This operation also sets the equivalent raw HTTP header.- If the proxy is not of type - HttpProxyor- HttpCachingProxythis has no effect.- See also - setHeaders(newHeaders)¶
- Parameters:
- newHeaders – - QHttpHeaders
 
 - setHostName(hostName)¶
- Parameters:
- hostName – str 
 
 - Sets the host name of the proxy host to be - hostName.- See also - setPassword(password)¶
- Parameters:
- password – str 
 
 - Sets the password for proxy authentication to be - password.- See also - setPort(port)¶
- Parameters:
- port – int 
 
 - Sets the port of the proxy host to be - port.- See also - setRawHeader(headerName, value)¶
- Parameters:
- headerName – - QByteArray
- value – - QByteArray
 
 
 - Warning - This section contains snippets that were automatically translated from C++ to Python and may contain errors. - Sets the header - headerNameto be of value- headerValue. If- headerNamecorresponds to a known header (see- KnownHeaders), the raw format will be parsed and the corresponding “cooked” header will be set as well.- For example: - request.setRawHeader(QByteArray("Last-Modified"), QByteArray("Sun, 06 Nov 1994 08:49:37 GMT")) - will also set the known header LastModifiedHeader to be the QDateTime object of the parsed date. - Note - Setting the same header twice overrides the previous setting. To accomplish the behaviour of multiple HTTP headers of the same name, you should concatenate the two values, separating them with a comma (“,”) and set one single raw header. - If the proxy is not of type - HttpProxyor- HttpCachingProxythis has no effect.- See also - Sets the proxy type for this instance to be - type.- Note that changing the type of a proxy does not change the set of capabilities this - QNetworkProxyobject holds if any capabilities have been set with- setCapabilities().- See also - setUser(userName)¶
- Parameters:
- userName – str 
 
 - Sets the user name for proxy authentication to be - user.- See also - swap(other)¶
- Parameters:
- other – - QNetworkProxy
 
 - Swaps this network proxy instance with - other. This operation is very fast and never fails.- Returns the proxy type for this instance. - See also - user()¶
- Return type:
- str 
 
 - Returns the user name used for authentication. - See also