A raw Python socket does not negotiate a proxy because http_proxy exists. For an application speaking its own TCP protocol, use a connector that understands the service at the proxy endpoint.

With PySocks already available, create the connection explicitly:

import socks

with socks.socksocket() as connection:
    connection.set_proxy(socks.SOCKS5, '203.0.113.10', 1080)
    connection.settimeout(10)
    connection.connect(('example.com', 12345))
    # Exchange the destination protocol here.

Replace the documentation address and destination port. For an allowed public destination, select a candidate from the SOCKS5 proxy list only after checking that it permits the application's target port. Check the installed package, supported methods and endpoint requirements against the PySocks interface.

The rest of the application exchanges its protocol over this established connection. If that protocol uses TLS, start it after proxy negotiation and verify the real destination hostname. Proxy authentication establishes the route; it does not provide the destination login or encryption.

A SOCKS listener needs SOCKS negotiation. An HTTP service needs a CONNECT-capable connector for an arbitrary TCP destination and may deny its port. Choose the connector from the service actually offered, rather than changing an address while leaving the wrong handshake.

Keep replacement local. Assigning a class to socket.socket can affect unrelated imports and libraries. If another library owns socket creation, use its documented connection factory or proxy option; a dictionary it never reads cannot change that connection.

Ũhoro ũhĩtĩte