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
- Host: GitHub
- URL: https://github.com/gableroux/prevent-unicode-encode-ascii-error
- Owner: GabLeRoux
- Created: 2018-09-25T15:25:03.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2018-09-25T15:25:13.000Z (over 7 years ago)
- Last Synced: 2025-02-05T23:58:56.980Z (12 months ago)
- Topics: ascii, encode, error, example, python, unicode
- Homepage:
- Size: 0 Bytes
- Stars: 3
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: ReadMe.md
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