You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Getting 'NoneType' object has no attribute 'encoding' when running with pythonw (non-CLI)
Believe due to "pythonw" has NO standard streams sys.stdin, sys.stdout and sys.stderr available
No problem when running with "python" (with CLI)
File "\Local\Programs\Python\Python38-32\lib\site-packages\winwifi\main.py", line 188, in connect
aps: List['WiFiAp'] = cls.scan()
File "\Local\Programs\Python\Python38-32\lib\site-packages\winwifi\main.py", line 162, in scan
cp: subprocess.CompletedProcess = cls.netsh(['wlan', 'show', 'networks', 'mode=bssid'])
File "\Local\Programs\Python\Python38-32\lib\site-packages\winwifi\main.py", line 100, in netsh
timeout=timeout, check=check, encoding=sys.stdout.encoding) AttributeError: 'NoneType' object has no attribute 'encoding'
Hi! I've fixed that issue with my pull request, setting the encoding to UTF-8. The reason you had the bug was because it sets the encoding to whatever encoding you're using in your command line. If you python without the command line, like a .pyw file, than sys.stdout doesn't exist, since it's basically the command line. In short, just change sys.stdout.encoding to python's default, "UTF-8".
Getting 'NoneType' object has no attribute 'encoding' when running with pythonw (non-CLI)
Believe due to "pythonw" has NO standard streams sys.stdin, sys.stdout and sys.stderr available
No problem when running with "python" (with CLI)
File "\Local\Programs\Python\Python38-32\lib\site-packages\winwifi\main.py", line 188, in connect
aps: List['WiFiAp'] = cls.scan()
File "\Local\Programs\Python\Python38-32\lib\site-packages\winwifi\main.py", line 162, in scan
cp: subprocess.CompletedProcess = cls.netsh(['wlan', 'show', 'networks', 'mode=bssid'])
File "\Local\Programs\Python\Python38-32\lib\site-packages\winwifi\main.py", line 100, in netsh
timeout=timeout, check=check, encoding=sys.stdout.encoding)
AttributeError: 'NoneType' object has no attribute 'encoding'
@classmethod
def netsh(cls, args: List[str], timeout: int = 3, check: bool = True) -> subprocess.CompletedProcess:
return subprocess.run(
['netsh'] + args, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE,
timeout=timeout, check=check, encoding=sys.stdout.encoding) <------------- HERE
The text was updated successfully, but these errors were encountered: