Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mimetypes.MimeType UnicodeDecodeError #65337

Closed
tanbro mannequin opened this issue Apr 3, 2014 · 5 comments
Closed

mimetypes.MimeType UnicodeDecodeError #65337

tanbro mannequin opened this issue Apr 3, 2014 · 5 comments
Assignees
Labels
stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@tanbro
Copy link
Mannequin

tanbro mannequin commented Apr 3, 2014

BPO 21138
Nosy @terryjreedy, @tjguk

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = 'https://github.com/tjguk'
closed_at = <Date 2014-04-29.12:42:31.321>
created_at = <Date 2014-04-03.01:39:20.196>
labels = ['type-bug', 'library']
title = 'mimetypes.MimeType UnicodeDecodeError'
updated_at = <Date 2014-04-29.12:42:31.320>
user = 'https://bugs.python.org/tanbro'

bugs.python.org fields:

activity = <Date 2014-04-29.12:42:31.320>
actor = 'tim.golden'
assignee = 'tim.golden'
closed = True
closed_date = <Date 2014-04-29.12:42:31.321>
closer = 'tim.golden'
components = ['Library (Lib)']
creation = <Date 2014-04-03.01:39:20.196>
creator = 'tanbro'
dependencies = []
files = []
hgrepos = []
issue_num = 21138
keywords = []
message_count = 5.0
messages = ['215414', '215418', '216988', '217010', '217515']
nosy_count = 4.0
nosy_names = ['terry.reedy', 'tim.golden', 'python-dev', 'tanbro']
pr_nums = []
priority = 'normal'
resolution = 'duplicate'
stage = 'resolved'
status = 'closed'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue21138'
versions = ['Python 2.7']

@tanbro
Copy link
Mannequin Author

tanbro mannequin commented Apr 3, 2014

when new a mimetypes.MimeType instance in a my Windows, whose default coding is mbcs, UnicdeDecodeError occurred.

Python 2.7.6 (default, Nov 10 2013, 19:24:18) [MSC v.1500 32 bit (Intel)] on win
32
Type "help", "copyright", "credits" or "license" for more information.
>>> from mimetypes import MimeTypes
>>> mt = MimeTypes()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "D:\Python27\lib\mimetypes.py", line 66, in __init__
    init()
  File "D:\Python27\lib\mimetypes.py", line 358, in init
    db.read_windows_registry()
  File "D:\Python27\lib\mimetypes.py", line 258, in read_windows_registry
    for subkeyname in enum_types(hkcr):
  File "D:\Python27\lib\mimetypes.py", line 249, in enum_types
    ctype = ctype.encode(default_encoding) # omit in 3.x!
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc7 in position 8: ordinal
not in range(128)

i think this error was caused by the code in mimetypes.py's line 256

default_encoding = sys.getdefaultencoding() 

if change this line to:

default_encoding = sys.getfilesystemencoding()

such error will be resolved

@tanbro tanbro mannequin added stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error labels Apr 3, 2014
@tanbro
Copy link
Mannequin Author

tanbro mannequin commented Apr 3, 2014

and in line 249, changes:

if isinstance(ctype, unicode):
    ctype = ctype.encode(default_encoding) # omit in 3.x!

@terryjreedy
Copy link
Member

The unlinked push message was for bpo-21139.

@tjguk
Copy link
Member

tjguk commented Apr 22, 2014

This looks like a duplicate of bpo-9291; could you test the latest patch over there, please?

@tjguk tjguk self-assigned this Apr 22, 2014
@tjguk
Copy link
Member

tjguk commented Apr 29, 2014

Fixed by bpo-9291

@tjguk tjguk closed this as completed Apr 29, 2014
@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

2 participants