0

Hi When I try to run my Python program

The program runs well with torsocks

But when the program needs to connect to the database (postgresql) Gives an error and can not

How to configure the tor so that our program can find the database?

I use the postgresql

Photo of Error: 1

It does not matter if my program is a Django or I use a sqlalchemy Cannot find database at all

oem@khoramfar$: proxychains curl https://api.ipify.org/
    [proxychains] config file found: /etc/proxychains.conf
    [proxychains] preloading /usr/lib/x86_64-linux-gnu/libproxychains.so.4
    [proxychains] DLL init: proxychains-ng 4.14
    [proxychains] Dynamic chain  ...  109.194.114.100:8081  ...  178.128.235.170:3128 <--denied
    [proxychains] Dynamic chain  ...  109.194.114.100:8081  ...  51.68.198.158:80 <--denied
    [proxychains] Dynamic chain  ...  109.194.114.100:8081  ...  68.183.192.29:8080 <--denied
    [proxychains] Dynamic chain  ...  109.194.114.100:8081  ...  93.91.86.102:8080 <--denied
    [proxychains] Dynamic chain  ...  109.194.114.100:8081  ...  41.237.65.105:80 <--denied
    [proxychains] Dynamic chain  ...  109.194.114.100:8081  ...  115.124.115.26:80 <--denied
    [proxychains] Dynamic chain  ...  109.194.114.100:8081  ...  41.59.254.172:80 <--denied
    [proxychains] Dynamic chain  ...  109.194.114.100:8081  ...  1.20.103.196:42792 <--denied
    [proxychains] Dynamic chain  ...  109.194.114.100:8081  ...  115.85.75.34:80 <--denied
    [proxychains] Dynamic chain  ...  109.194.114.100:8081  ...  118.179.223.130:80 <--denied
    [proxychains] Dynamic chain  ...  109.194.114.100:8081  ...  139.255.31.146:8080 <--denied
    [proxychains] Dynamic chain  ...  109.194.114.100:8081  ...  51.222.73.117:80 <--denied
    [proxychains] Dynamic chain  ...  109.194.114.100:8081  ...  timeout
    [proxychains] Dynamic chain  ...  178.128.125.16:35577  ...  111.90.179.74:8080 <--denied
    [proxychains] Dynamic chain  ...  178.128.125.16:35577  ...  96.47.231.58:8020 <--denied
    [proxychains] Dynamic chain  ...  178.128.125.16:35577  ...  167.172.184.166:40607  ...  185.18.214.13:8080  ...  178.128.125.16:34534  ...  106.51.252.227:80 <--socket error or timeout!
    [proxychains] Dynamic chain  ...  178.128.125.16:35577  ...  167.172.184.166:40607  ...  185.18.214.13:8080  ...  178.128.125.16:34534  ...  59.14.228.31:80 <--socket error or timeout!
    [proxychains] Dynamic chain  ...  178.128.125.16:35577  ...  167.172.184.166:40607 <--denied
    [proxychains] Dynamic chain  ...  178.128.125.16:35577  ...  185.18.214.13:8080 <--socket error or timeout!
    [proxychains] Dynamic chain  ...  178.128.125.16:35577  ...  178.128.125.16:34534  ...  23.21.48.44:443 <--socket error or timeout!
    [proxychains] Dynamic chain  ...  178.128.125.16:35577  ...  178.128.125.16:34534  ...  23.21.140.41:443  ...  OK

185.220.100.251

when i use proxychains my ip changes but when i run the program stil get that error

  • please provide your code or piece of code related to the error message – eshirvana Mar 30 '21 at 22:13
  • @eshirvana my database settings: `DATABASES = { 'default': { 'ENGINE': 'django.db.backends.postgresql_psycopg2', 'NAME': 'sxaww22', 'USER': 'postgres', 'PASSWORD': '1236', 'HOST': 'localhost', 'PORT': '', } }` – Hamidreza Khorammfar Mar 31 '21 at 09:23

1 Answers1

1

You won't be able to connect to a local database from within the program if you run it through torsocks because this intercepts all socket calls to route them over Tor. Routing all connections through Tor like that means there is no more localhost (can't access 127.0.0.1) and the database connection will go over Tor.

If you have some HTTP requests that need to be routed through Tor in the program and you can change the source, you'll need to proxy those requests over SOCKS through Tor so only the relevant HTTP traffic uses Tor and other connections (like database) continue to work as usual.

drew010
  • 68,777
  • 11
  • 134
  • 162
  • How do we do this? I do not know exactly how – Hamidreza Khorammfar Apr 01 '21 at 11:22
  • It'll depend on what HTTP library is being used in the program. If it's python-requests, set the `proxies` option as shown in Part 1 here: https://stackoverflow.com/a/33875657/892493 – drew010 Apr 01 '21 at 15:32
  • I do not use the `requests` library The program is a telegram robot that uses `postgres` In general, I misunderstood what you meant Do you mean to use `HTTPTunnelPort PORT` on the tor? And build a tunnel HTTP as a whole? I do not use the request library (Should I use `HTTP` proxies at all?) – Hamidreza Khorammfar Apr 01 '21 at 17:26
  • Does it use urllib? – drew010 Apr 01 '21 at 20:53
  • My program is Telegram Robot and I want to change the IP robot before it turns on I do not want to use a proxy with the robot itself I need to change the IP before connecting the robot – Hamidreza Khorammfar Apr 01 '21 at 21:46
  • A proxy will be the only way to get it to use Tor, since it is incompatible with Torsocks due to how it uses Postgres for a local database connection. – drew010 Apr 01 '21 at 22:34
  • So what is the solution? – Hamidreza Khorammfar Apr 02 '21 at 12:06
  • Modify the program to route the require HTTP requests through Tor's socks proxy. You stated it doesn't use requests, and didn't indicate if it uses urllib so I don't know how to help. The source code needs to be changed to support SOCKS proxies for HTTP within the program, if you're willing and able. – drew010 Apr 02 '21 at 18:13
  • My program is Telegram Robot – Hamidreza Khorammfar Apr 03 '21 at 14:50