Reputation: 73
I'm trying to establish a connection to a PostgreSQL database over a SOCKS5 proxy in Python using the PySocks
library. Here's the approach I'm currently using:
import socks
import socket
# Configure socks proxy
socks.set_default_proxy(socks.SOCKS5, proxy_host, proxy_port, username=proxy_username, password=proxy_password)
socket.socket = socks.socksocket
# Establish the database connection as usual
This method successfully routes my PostgreSQL connection through the SOCKS5 proxy. However, it modifies the global default socket object, which affects all network connections made by the process, forcing them to go through the SOCKS5 proxy. This is not desirable as I only want the PostgreSQL connection to be routed through the proxy, not all network activity.
Questions:
I appreciate any guidance or suggestions on how to address this issue!
Upvotes: 0
Views: 751