kboghe / NordVPN-switcher

Rotate between different NordVPN servers with ease. Works both on Linux and Windows without any required changes to your code!
https://pypi.org/project/nordvpn-switcher/
189 stars 51 forks source link

Encountering "The handle is invalid" error when using subprocess.Popen with shell=True #56

Open karl-an opened 4 months ago

karl-an commented 4 months ago

Description

I'm encountering an error when using nordvpn_switcher to interact with the NordVPN application. I run it from RStudio. Freshly installed Python. The error message is:

OSError: [WinError 6] The handle is invalid

This error occurs specifically in the initialize_VPN function on line 152 of nordvpn_switch.py. The relevant code snippet is:

open_nord_win = subprocess.Popen(["nordvpn", "-d"], shell=True, cwd=cwd_path, stdout=DEVNULL)

I understand the security concerns associated with using shell=True and have explored alternative approaches. I've reviewed the documentation but haven't found a documented method to bypass external commands for running NordVPN actions.

Steps to reproduce:

  1. Install nordvpn_switcher.
  2. Run a script that utilizes nordvpn_switcher and attempts to connect or disconnect using the library.

Expected behavior:

The nordvpn_switcher library should successfully interact with the NordVPN application without encountering any errors.

Actual behavior:

The script throws the "The handle is invalid" error when the initialize_VPN function attempts to run the nordvpn command using subprocess.Popen with shell=True.

Additional context:

I would appreciate any guidance or assistance in resolving this issue.

Thank you for your time and support.