Skip to content

Bug fix for encoding of b_whitespace - Similar to closed issue #272 - #346

Merged
aclark4life merged 3 commits into
python-pillow:masterfrom
mhogg:master
Sep 30, 2013
Merged

aclark4life merged 3 commits into
python-pillow:masterfrom
mhogg:master

Conversation

@mhogg

@mhogg mhogg commented Sep 30, 2013

Copy link
Copy Markdown
Contributor

Hi,

Having recently changed from PIL to Pillow for creating images, I have been getting an error similar to that previously reported in Issue #272. Something like:

b_whitespace = string.whitespace.encode()
UnicodeDecodeError: 'ascii' codec can't decode byte 0xa0 in position 6: ordinal not in range(128)

In my case it was when I use Image.save() rather than Image.open().
I am using the Python API that is built into a commercial Finite Element Analysis package, so it is not a standard Python installation. The locale for this Python installation is ('English_United States', '1252').

I think that this error can easily be fixed by first decoding string.whitespace using the current locale and then encoding to ascii. It should also work in the other problem cases where the locale has been changed.

Cheers,
Michael

Bug fix for encoding of b_whitespace
Bug fix when locale has not been set
Making it work for Python 3.x
@mhogg

mhogg commented Sep 30, 2013

Copy link
Copy Markdown
Contributor Author

I have updated this patch:

  • So that it works when locale.getlocale() returns (None,None) by falling back to the values from locale.getdefaultlocale()
  • So that it works with Python 3.x - Do not need to decode a string in Python 3.x

@mhogg mhogg closed this Sep 30, 2013
@mhogg mhogg reopened this Sep 30, 2013
@mhogg mhogg closed this Sep 30, 2013
@mhogg mhogg reopened this Sep 30, 2013
aclark4life added a commit that referenced this pull request Sep 30, 2013
Bug fix for encoding of b_whitespace - Similar to closed issue #272
@aclark4life
aclark4life merged commit 946af1e into python-pillow:master Sep 30, 2013
@aclark4life

Copy link
Copy Markdown
Member

Thanks

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants