Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions news/4310.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Works around UnicodeDecodeError using ``repr()`` in decoding console output on
Python 3.
10 changes: 9 additions & 1 deletion pip/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import os
import sys
import warnings

from pip._vendor.six import text_type

Expand Down Expand Up @@ -41,7 +42,14 @@ def console_to_str(s):
try:
return s.decode(sys.__stdout__.encoding)
except UnicodeDecodeError:
return s.decode('utf_8')
try:
return s.decode('utf_8')
except UnicodeDecodeError:
warnings.warn(
'Could not detect stdout encoding - falling back to repr',
category=RuntimeWarning, stacklevel=2)
# Decode at least line breaks manually
return repr(s)[2:-1].replace('\\r', '\r').replace('\\n', '\n')

def native_str(s, replace=False):
if isinstance(s, bytes):
Expand Down