[PyQt] Fwd: UnicodeDecodeError with output from Windows OS command

J Barchan jnbarchan at gmail.com
Fri Dec 1 13:47:06 GMT 2017


On 1 December 2017 at 12:18, Florian Bruhin <me at the-compiler.org> wrote:

>
>
> Yes, thinking about it again, I was wrong there - sorry! If you can't force
> robocopy to output UTF-8, the best (and probably correct) guess is
> ​​
> locale.getpreferredencoding():
> https://docs.python.org/3/library/locale.html#locale.getpreferredencoding
>
> The documentation for subprocess mentions that it's using
> locale.getpreferredencoding(False) if no encoding was given. I'm still
> not sure
> what that argument (do_setlocale) means exactly, but you might want to
> just do
> the same.
>

​Dear Florian,

This is *almost* what I was always looking for, which nobody has come up
with till now...!!!  But read on....

All the people elsewhere who have been saying use utf-8 or utf-16 or the
file system encoding or all the other things have been doing my head in...
:(

After I had penned my long epistle to you earlier, I discovered that,
although some of the solutions had *appeared* to work in that I no longer
got the conversion error, ​it turns out they were then *displaying* that £
character differently, e.g. as the "oe" character or other symbol.

I discovered for myself that *only* decode("cp850") caused it to display as
the desired £.  And that's because UK/Western Europe is *Code Page 850*.
So it all fits together now!

Now, I *assumed* your suggestion of ​locale.getpreferredencoding() would
return cp850 under Windows (remember, I do not have Windows python to
test).  But I checked with my Windows stakeholder, and it does not --- it
returns the "windows_1252" type string, which we know does *not* get the £
right....

Then, I got him to open a Command Prompt, and just enter the command:

c:\Tmp> *chcp*
> Active code page: 850
>

That response from chcp of 850 as the CP is precisely what I am looking
for....!!!

*Soooo*, I have a little request-task for you!  Assuming you have Windows +
Python 3, can you find a native Qt/PyQt/Python call which returns that
under Windows, please, please??  If you're not UK, obviously your CP value
may vary, but you know what I'm seeking.  Thank you so much!

BTW, in http://doc.qt.io/qt-5/qprocess.html I do not see any mention of
"encoding at all"?  Where were you getting your second paragraph above from?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20171201/c55dd52e/attachment.html>


More information about the PyQt mailing list