ProxyAgent connects through the endpoint supplied to it. For a plain HTTP request and a proxy that accepts Basic authentication, put the proxy login on that request’s Proxy-Authorization header.

import base64
from twisted.internet.endpoints import TCP4ClientEndpoint
from twisted.web.client import ProxyAgent
from twisted.web.http_headers import Headers

endpoint = TCP4ClientEndpoint(reactor, 'proxy.example', 8080,
                              timeout=5)
agent = ProxyAgent(endpoint, reactor=reactor)
token = base64.b64encode(b'alice:REPLACE_WITH_PROXY_PASSWORD')
headers = Headers({b'Proxy-Authorization': [b'Basic ' + token]})
pending = agent.request(b'GET', b'http://example.com/', headers)

This fragment assumes the application already has its reactor. The method, URI and illustrated header data use bytes. Keep real credentials in the application’s credential source; the placeholder only shows how the header is constructed. Base64 is an encoding, so confidentiality depends on the connection carrying it.

The returned Deferred yields a response object. Receiving that object does not collect the response body; consume it through the documented body-reading interface and handle asynchronous failures. The endpoint timeout bounds connection establishment, not the complete response lifetime.

The example intentionally uses an HTTP destination. It does not add a CONNECT negotiation for HTTPS merely by changing the URI scheme.

ХӀокхунах тера йаззамаш