Jamie- / openvpn-api

A Python API for the OpenVPN management interface.
MIT License
56 stars 19 forks source link

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

Open SadafShafi opened 4 years ago

SadafShafi commented 4 years ago

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

D0han commented 4 years ago

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

SadafShafi commented 4 years ago

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

Divyanshsingh-dev commented 3 years ago

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

HosseyNJF commented 3 years ago

Send your OpenVPN configuration and your code.

rcolpo commented 3 years ago

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.

HosseyNJF commented 3 years ago

@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)

rcolpo commented 3 years ago

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.

HosseyNJF commented 3 years ago

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

shagunkam commented 10 months ago

<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??