NordVPN-switcher icon indicating copy to clipboard operation
NordVPN-switcher copied to clipboard

fixed Issue 54- UnicodeEncodeError when running via terminal in windows

Open eranga-mohotty opened this issue 1 year ago • 0 comments

Description

Fix for Issue #54 - UnicodeEncodeError when running via terminal in windows

Motivation and Context

When executing a python script via a batch script (.bat) and calling the function initialize_VPN(...) it will throw a UnicodeEncodeError this update will set the encoding to 'utf-8'. However this issue is only fixed for python versions 3.7 and above as the "sys.stdout.reconfigure()" method is available starting from 3.7

Changes Made

import sys [+line 10]

[+lines 129-136]

# Check if the platform is Windows
if platform.system() == 'Windows':
    # Change the encoding to 'utf-8' for Windows terminal
    if sys.version_info >= (3, 7):
        try:
            sys.stdout.reconfigure(encoding='utf-8')
        except Exception as e:
            print(f"An error occurred while reconfiguring stdout: {e}")

eranga-mohotty avatar Jan 21 '24 02:01 eranga-mohotty