Skip to content

Fix UnicodeDecodeError when OpenSSL is not found#2181

Merged
HelloZeroNet merged 1 commit intoHelloZeroNet:py3from
purplesyringa:patch-1
Sep 2, 2019
Merged

Fix UnicodeDecodeError when OpenSSL is not found#2181
HelloZeroNet merged 1 commit intoHelloZeroNet:py3from
purplesyringa:patch-1

Conversation

@purplesyringa
Copy link
Copy Markdown
Contributor

Fixes #2180

@HelloZeroNet
Copy link
Copy Markdown
Owner

HelloZeroNet commented Sep 2, 2019

It would be better to figure out how to decode the result properly. I was unable to reproduce the error as I have english system installed, but I did tried this way:

import subprocess

print("Default encoding:")
proc = subprocess.Popen(
    "chcp", shell=True, stderr=subprocess.STDOUT,
    stdout=subprocess.PIPE
)
print(proc.stdout.read())

cmd = """powershell Write-Host \xe1rv\xedzt\u0171r\u0151"""
for code_page in [852, 65001]:
	subprocess.call("chcp %s" % code_page, shell=True)
	proc = subprocess.Popen(
	    cmd, shell=True, stderr=subprocess.STDOUT,
	    stdout=subprocess.PIPE
	)
	back = proc.stdout.read()
	print("- Running:", cmd)
	print("Back:", back)
	print("Back.decode(errors='replace'):", back.decode(errors="replace"))

Output:

Default encoding:
b'Active code page: 852\r\n'
Active code page: 852
- Running: powershell Write-Host árvíztűrő
Back: b'\xa0rv\xa1zt\xfbr\x8b\n'
Back.decode(errors='replace'): �rv�zt�r�

Active code page: 65001
- Running: powershell Write-Host árvíztűrő
Back: b'\xc3\xa1rv\xc3\xadzt\xc5\xb1r\xc5\x91\n'
Back.decode(errors='replace'): árvíztűrő

Based on this it would be more proper fix add

if sys.platform.startswith("win"):
   subprocess.call("chcp 65001", shell=True)

To beginning of the function or to main.py as it effects other subprocess executions as well.

@purplesyringa
Copy link
Copy Markdown
Contributor Author

Ok, that makes sense. It's still worth merging this PR until we come up with a better solution.

@HelloZeroNet HelloZeroNet merged commit b9e71c9 into HelloZeroNet:py3 Sep 2, 2019
@purplesyringa
Copy link
Copy Markdown
Contributor Author

For the record: this is now replaced with a better fix

@purplesyringa purplesyringa deleted the patch-1 branch September 3, 2019 12:31
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

Successfully merging this pull request may close these issues.

UnicodeDecodeError when start ZeroNet.

2 participants