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
time.strptime() fails with unicode date string, de_DE locale #42332
Comments
Trying to parse a German date string fails in Python Since there's no indenting, I suppose the test case can import locale, time
locale.setlocale(locale.LC_TIME, 'de_DE')
date = u'10. September 2005 um 17:26'
format = '%d. %B %Y um %H:%M'
time.strptime(date, format) -- |
Logged In: YES Here's a simpler, more precise test case (also attached): import locale, time
locale.setlocale(locale.LC_TIME, 'de_DE')
date = u'September'; format = '%B'
time.strptime(date, format) Here's the error I see: Traceback (most recent call last):
File "de_strptime_fail_simple.py", line 4, in ?
time.strptime(date, format)
File "/usr/lib/python2.4/_strptime.py", line 329, in strptime
month = locale_time.f_month.index(found_dict['B'].lower())
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe4 in
position 1: ordinal not in range(128) |
Logged In: YES Can you let me know what time.strftime() outputs for your |
Logged In: YES I get a str from time.strftime(). >>> import time
>>> time.strftime('%B')
'September'
>>> time.strftime('%B').__class__
<type 'str'> |
Logged In: YES OK, then that settles it. If time.strftime() ever returned |
Logged In: YES Ok, sounds good. For anyone trying to work around this, unicode date strings import locale, time
locale.setlocale(locale.LC_TIME, 'de_DE')
date = u'September'.encode()
format = '%B'
time.strptime(date, format) -- |
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:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: