Didina Deen
Didina Deen

Reputation: 195

UnicodeDecodeError: 'utf8' codec can't decode byte

I'm using Django and ajax to print data to an HTML table with jQuery and JSON.

It was working until new data came and had "ú@ñ" type of characters and I got: UnicodeDecodeError: 'utf8' codec can't decode byte 0xf9 in position 4: invalid start byte

I've read and tried many different possible reasons and it's still not working.

I've tried:

I'd rather avoid using .decode() for every string in my data but if there's no other solution, it's what I'll have to do.

Upvotes: 0

Views: 2539

Answers (1)

Stanley Kirdey
Stanley Kirdey

Reputation: 631

-- encoding: utf-8

Is changing only encoding of the source file, meaning you can define variables/comments using non-ascii chars.

You can try to use

json.dumps(..., ensure_ascii=False, encoding="ISO-8859-1")

Upvotes: 1

Related Questions