Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting 'NoneType' object has no attribute 'encoding' when running with pythonw #13

Open
ermihusni opened this issue Jan 18, 2021 · 2 comments

Comments

@ermihusni
Copy link

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

@SpaceMonkeyAlfa
Copy link

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".

@SpaceMonkeyAlfa
Copy link

Sorry, correction to the above statement: use cp437 encoding instead of utf.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants