This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: test_mailcap fails if a mailcap file contains a non-decodable character
Type: Stage: needs patch
Components: Library (Lib) Versions: Python 3.4, Python 3.5
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: ned.deily, petrosr2
Priority: normal Keywords:

Created on 2015-05-09 20:45 by petrosr2, last changed 2022-04-11 14:58 by admin.

File name Uploaded Description Edit
results petrosr2, 2015-05-09 20:45
Repositories containing patches
Messages (3)
msg242840 - (view) Author: ryan (petrosr2) Date: 2015-05-09 20:45
msg242842 - (view) Author: ryan (petrosr2) Date: 2015-05-09 21:12
running command over PuTTY on Ubuntu 3.13, python 2.7.6

$ ./python -m test test_mailcap

[1/1] test_mailcap
test test_mailcap failed -- Traceback (most recent call last):
  File "/home/petrosr2/Documents/opensource/cpy/Lib/test/", line 126, in test_system_mailcap
    caps = mailcap.getcaps()
  File "/home/petrosr2/Documents/opensource/cpy/Lib/", line 26, in getcaps
    morecaps = readmailcapfile(fp)
  File "/home/petrosr2/Documents/opensource/cpy/Lib/", line 64, in readmailcapfile
    line = fp.readline()
  File "/home/petrosr2/Documents/opensource/cpy/Lib/encodings/", line 26, in decode
    return codecs.ascii_decode(input, self.errors)[0]
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 3820: ordinal not in range(128)

1 test failed:
msg242843 - (view) Author: Ned Deily (ned.deily) * (Python committer) Date: 2015-05-09 21:42
I can reproduce the failure by arbitrarily adding a non-ascii character to one of the mailcap files searched for by the mailcap module (, like $HOME/.mailcap, and by setting the process to an ascii-only locale (export LANG=C).  While this might be a somewhat unusual combination in practice, mailcap should be able to handle it.

By the way, this is a Python 3 problem since test_mailcap does not exist in Python 2.  2.7.6 might be the version of the system-supplied Python, but you appeared to be running with a Python you built.  Try

  ./python -V

to show the version of the Python you are using.
Date User Action Args
2022-04-11 14:58:16adminsetgithub: 68340
2015-05-09 21:42:06ned.deilysettype: crash ->
title: test_mailcap fails -> test_mailcap fails if a mailcap file contains a non-decodable character
components: + Library (Lib), - Tests

nosy: + ned.deily
versions: + Python 3.4, Python 3.5, - Python 2.7
messages: + msg242843
stage: needs patch
2015-05-09 21:12:22petrosr2setmessages: + msg242842
2015-05-09 20:45:44petrosr2create