question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

http: error: UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in position 1617: character maps to <undefined> when re-direction output to disk

See original GitHub issue

On Windows 10, I’m using httpie to retrieve data. It works fine when displaying on the screen, but as soon as I pipe the output to disk, I get http: error: UnicodeDecodeError: ‘charmap’ codec can’t decode byte 0x9d in position 8024: character maps to <undefined>

I tried to attach the file I’m having the problem with, but unfortunately, it 100Mb

Here is the complete debug output:

C:\Users\PeterKronenberg\Desktop>http --debug --print=Bb --pretty=all --session=C:\Users\PETERK~1\AppData\Local\Temp/access.json http://localhost:8080/nexus/extract/path  filePath=c:/TestFiles/100Mb.pdf > foo
HTTPie 2.3.0
Requests 2.25.1
Pygments 2.7.3
Python 3.9.1 (tags/v3.9.1:1e5d33e, Dec  7 2020, 17:08:21) [MSC v.1927 64 bit (AMD64)]
c:\python\python39\python.exe
Windows 10

<Environment {'colors': 256,
 'config': {'default_options': []},
 'config_dir': WindowsPath('C:/Users/PeterKronenberg/AppData/Roaming/httpie'),
 'devnull': <property object at 0x000001112C1815E0>,
 'is_windows': True,
 'log_error': <function Environment.log_error at 0x000001112C1AC1F0>,
 'program_name': 'http',
 'stderr': <colorama.ansitowin32.StreamWrapper object at 0x000001112C176F10>,
 'stderr_isatty': True,
 'stdin': <_io.TextIOWrapper name='<stdin>' mode='r' encoding='utf-8'>,
 'stdin_encoding': 'utf-8',
 'stdin_isatty': True,
 'stdout': <colorama.ansitowin32.StreamWrapper object at 0x000001112C176BE0>,
 'stdout_encoding': 'cp1252',
 'stdout_isatty': False}>

>>> requests.request(**{'auth': None,
 'data': '{"filePath": "c:/TestFiles/100Mb.pdf"}',
 'headers': {'User-Agent': b'HTTPie/2.3.0', 'Accept': b'application/json, */*;q=0.5', 'Content-Type': b'application/json', 'authorization': b'eyJhbGci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CWcW-r8l1Fn567s7SAFan-G37YeQYBfmwADI'},
 'method': 'post',
 'params': <generator object MultiValueOrderedDict.items at 0x000001112CA5FB30>,
 'url': 'http://localhost:8080/nexus/extract/path'})


http: error: UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in position 1617: character maps to <undefined>

Traceback (most recent call last):
  File "c:\python\python39\lib\runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "c:\python\python39\lib\runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "C:\Python\Python39\Scripts\http.exe\__main__.py", line 7, in <module>
  File "c:\python\python39\lib\site-packages\httpie\__main__.py", line 11, in main
    exit_status = main()
  File "c:\python\python39\lib\site-packages\httpie\core.py", line 79, in main
    exit_status = program(
  File "c:\python\python39\lib\site-packages\httpie\core.py", line 222, in program
    write_message(
  File "c:\python\python39\lib\site-packages\httpie\output\writer.py", line 38, in write_message
    write_stream_with_colors_win_py3(**write_stream_kwargs)
  File "c:\python\python39\lib\site-packages\httpie\output\writer.py", line 82, in write_stream_with_colors_win_py3
    outfile.write(chunk.decode(encoding))
  File "c:\python\python39\lib\encodings\cp1252.py", line 15, in decode
    return codecs.charmap_decode(input,errors,decoding_table)
UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in position 1617: character maps to <undefined>

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:12 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
Almadcommented, Jan 20, 2021

I think it may make sense to do it together / following the similar algorithm as #1022 for mismatches

0reactions
jakubroztocilcommented, Feb 3, 2021

Guidelines for a future fix:

  1. That issue relates specifically to colors, which can be enabled with both --format=all and --format=colors
  2. It is specific to Windows.
  3. It may have to do more with how colors are represented on Windows than with an encoding mismatch.

I’d find out what actually gets written to the file when colors are applied. And then see if it even makes sense to allow non-terminal coloured output on Windows: does cat ./output correctly reproduce the coloured output? Perhaps the best solution will be simply disabling colors on Windows unless the output is a terminal.

Read more comments on GitHub >

github_iconTop Results From Across the Web

'charmap' codec can't decode byte 0x9d in position 8024 ...
UnicodeDecodeError : 'charmap' codec can't decode byte 0x9d in position 8024: character maps to <undefined> when re-directing output to disk.
Read more >
UnicodeDecodeError: 'charmap' codec can't decode byte 0x8d ...
Answers related to “UnicodeDecodeError: 'charmap' codec can't decode byte 0x8d in position 32: character maps to <undefined>”. charmap codec can't encode ...
Read more >
'charmap' codec can't decode byte 0xX in position X: character ...
UnicodeDecodeError : ' charmap ' codec can't decode byte 0xX in position X: character maps to undefined, when trying to #open() and print...
Read more >
BASH Shell Redirect stderr To stdout ( redirect stderr to a File )
In short we can redirect stdout to a file simply using the > or >> symbol. Redirecting the standard error stream to a...
Read more >
'charmap' codec can't decode byte 0x9d in position 10442 ...
Re: UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in position 10442: character maps to <undefined>. From: Cameron Simpson <c.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found