Search code examples
pythonopenvpn

cannot connect to vpn using python-openvpn-client api


I have a pyhton program from which I am using python-openvpn-client API to connect to a vpn server using an .ovpn configuration file.

I have installed python 3.13.1 from the official website. Then I have created a virtual python environment to use in my python project.

I have successfully installed the python-openvpn-client (version 0.0.1) package which says it requires python >= 3.9. I have used below command to install it in my virtual environment:

pip install python-openvpn-client

I installed OpenVpn from here. I am using version OpenVPN 2.6.12 - Released 18 July 2024.

Then I do below:

from openvpnclient import OpenVPNClient

def connect_to_vpn(config_path):
    vpn = OpenVPNClient(config_path)

    try:
        vpn.connect()
        while not vpn.is_connected():
            print(f"Status: {vpn.status}")
            sleep(2)

        print("Connection successfully established.")
        return vpn
    except Exception as e:
        print(f"Error connecting to VPN server: {e}")
        return None

config_path is the full path to an .ovpn file.

When executing the line of code vpn.connect() an exception is thrown:

module 'signal' has no attribute 'SIGUSR1'

If I import the same .ovpn file from OpenVPN app and connect to the the VPN server, then is working but not from my python program.

My platform is Windows 10 Pro.

So what am I doing wrong?


Solution

  • The python-openvpn-client 0.0.1 is for Unix-like systems like Linux, macOS or BSD. It's page says it was tested to work on macOS and Linux.
    The Windows systems do not support POSIX signals like SIGUSR1. You had this error message because SIGURS1 is not defined.
    The POSIX signals are supported on Unix-like systems.

    You could try openvpn-api.