8000 python 2.x compatibility · Issue #168 · python-openxml/python-docx · GitHub
[go: up one dir, main page]

Skip to content

python 2.x compatibility #168

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

Closed
snodo opened this issue Mar 30, 2015 · 1 comment
Closed

python 2.x compatibility #168

snodo opened this issue Mar 30, 2015 · 1 comment

Comments

@snodo
Copy link
snodo commented Mar 30, 2015

there is a problem in
CT_CoreProperties._set_element_text (line 299)

value = str(value)

which will will fail in a default windows-python2.x installation when supplying unicode strings (e.g.):

UnicodeEncodeError: 'ascii' codec can't encode character u'\xfc' in position 0: ordinal not in range(128)

This is because there is no default system encoding, so python tries to encode the unicode-string using 7-bit-ASCII, which of course fails.

My solution: Only convert to string, if its necessary. If it's already a string/unicode, don't touch.

if not isinstance(value, basestring):
    value = str(value)
@scanny
Copy link
Contributor
scanny commented Aug 18, 2018

Fixed in release v0.8.7 circa Aug 18 2018.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants
0