An open API service indexing awesome lists of open source software.

https://github.com/gableroux/prevent-unicode-encode-ascii-error

📚Notes concerning unicode encoding with python
https://github.com/gableroux/prevent-unicode-encode-ascii-error

ascii encode error example python unicode

Last synced: 10 months ago
JSON representation

📚Notes concerning unicode encoding with python

Awesome Lists containing this project

README

          

## Example:

```
Traceback (most recent call last):
File "foobar.py", line 792, in
print value
UnicodeEncodeError: 'ascii' codec can't encode character u'\xa0' in position 20: ordinal not in range(128)
```

## From python

```python
import sys
import codecs
sys.stdout = codecs.getwriter('utf8')(sys.stdout)
sys.stderr = codecs.getwriter('utf8')(sys.stderr)
```

## When invoking a command

```bash
export PYTHONIOENCODING=UTF-8
```

or

```bash
PYTHONIOENCODING=UTF-8 ./manage.py runserver
```

source: https://chase-seibert.github.io/blog/2014/01/12/python-unicode-console-output.html