openvpn-api icon indicating copy to clipboard operation
openvpn-api copied to clipboard

No connection could be made because the target machine actively refused it

Open SadafShafi opened this issue 4 years ago • 9 comments

I ran this script import openvpn_api.vpn v = openvpn_api.vpn.VPN('localhost', 7505) v.connect() print(" ______________ connected _______________") print(v.release) v.disconnect()

and this is the error I got Traceback (most recent call last): File "vpn123.py", line 5, in <module> v.connect() File "C:\Users\sadaf\AppData\Local\Programs\Python\Python38-32\lib\site-packages\openvpn_api\vpn.py", line 63, in connect raise errors.ConnectError(str(e)) from None openvpn_api.util.errors.ConnectError: [WinError 10061] No connection could be made because the target machine actively refused it

SadafShafi avatar Sep 25 '20 15:09 SadafShafi

Do you have openvpn running and exposing management interface on localhost tcp 7505? Keep in mind any firewalls you may have in place.

D0han avatar Sep 25 '20 15:09 D0han

Thanks for the reply No, i dont have any of such things running along

SadafShafi avatar Sep 25 '20 17:09 SadafShafi

I am getting the same problem and I have No Firewall Please HELP!

Divyanshsingh-dev avatar Dec 09 '20 14:12 Divyanshsingh-dev

Send your OpenVPN configuration and your code.

HosseyNJF avatar Dec 09 '20 15:12 HosseyNJF

I also can not connect. My OpenVPN configuration file is located in the current working directory, and in C:\X\OpenVPN\config. The config file is:

client
dev tun
proto udp
remote bcn-239.whiskergalaxy.com 443

nobind
auth-user-pass

resolv-retry infinite

auth SHA512
cipher AES-256-CBC
comp-lzo
verb 2
mute-replay-warnings
remote-cert-tls server
persist-key
persist-tun

key-direction 1
<ca>
-----BEGIN CERTIFICATE-----
...
-----END CERTIFICATE-----
</ca>
<tls-auth>
-----BEGIN OpenVPN Static key V1-----
...
-----END OpenVPN Static key V1-----
</tls-auth>

To connect, I'm doing

import openvpn_api
v = openvpn_api.VPN('bcn-239.whiskergalaxy.com', 443)
v.connect()

But I receive a time out error. I can connect using the OpenVPN GUI, but I would like to have a Python interface.

rcolpo avatar Jan 09 '21 14:01 rcolpo

@rcolpo Add another entry to your config like this: management localhost 7505 And then connect to it this way: v = openvpn_api.VPN('localhost', 7505)

HosseyNJF avatar Jan 09 '21 17:01 HosseyNJF

Thank you @HosseyNJF. I changed the config file like the one below:

client
dev tun
proto udp
remote bcn-239.whiskergalaxy.com 443

management localhost 7505

nobind
auth-user-pass

resolv-retry infinite

auth SHA512
cipher AES-256-CBC
comp-lzo
verb 2
mute-replay-warnings
remote-cert-tls server
persist-key
persist-tun

key-direction 1
<ca>
-----BEGIN CERTIFICATE-----
...
-----END CERTIFICATE-----
</ca>
<tls-auth>
-----BEGIN OpenVPN Static key V1-----
...
-----END OpenVPN Static key V1-----
</tls-auth>

Then, I tried to connect like this:

import openvpn_api
v = openvpn_api.VPN('localhost', 7505)
v.connect()

But I got the error: No connection could be made because the target machine actively refused it

I can no longer connect using the OpenVPN GUI.

rcolpo avatar Jan 10 '21 02:01 rcolpo

@rcolpo Are you running both the python code and the OpenVPN server on the same machine?

HosseyNJF avatar Jan 12 '21 09:01 HosseyNJF

<openvpn_api.vpn.VPN object at 0x7f85e86d8430> Traceback (most recent call last): File "1.py", line 12, in v.connect() File "/home/itechnolabs/vpn/env/lib/python3.8/site-packages/openvpn_api/vpn.py", line 63, in connect raise errors.ConnectError(str(e)) from None openvpn_api.util.errors.ConnectError: timed out

any help??

shagunkam avatar Dec 01 '23 11:12 shagunkam