Skip to content
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

Incorrect encoding #6

Closed
ghost opened this issue Jan 21, 2018 · 5 comments
Closed

Incorrect encoding #6

ghost opened this issue Jan 21, 2018 · 5 comments

Comments

@ghost
Copy link

ghost commented Jan 21, 2018

Hi

Just been helping a friend debug some encoding issue with the API. Namely, the example we were on was for https://github.com/adrpadua/5e-database/blob/master/5e-SRD-Spells.json#L18.

Seems Windows-1252 has been stored as UTF-8 or vice versa (not quite sure which way around it is).

Solution for us was to do the following.

import requests

res = requests.get('http://www.dnd5eapi.co/api/spells/1')
data = res.json()

print(data['material'])
>>> 'Powdered rhubarb leaf and an adder’s stomach.'

data['material'] = data['material'].encode('windows-1252').decode('utf-8')
print(data['material'])
>>> 'Powdered rhubarb leaf and an adder’s stomach.'

The HTTP response headers are being sent in UTF-8 format, which is why I reckon this is being sent wrong, rather than being corrected by the library when it detects the encoding.

Hope this is of help.

@bobifle
Copy link

bobifle commented May 10, 2018

I have the same issue, seems to have been introduced by the commit 8dacafd in 5e-SRD-Spells.json

@gabenunez
Copy link

@neko404notfound Thanks for the direction on this!

I'm currently running a discord.js bot in node.js and had to install the UTF-8 and windows1252 modules to get this to work.

item = utf8.decode(windows1252.encode(item));

@justingolden21
Copy link

Here's what I've been doing (replacing strings):

itemDescription = itemDescription.split('’').join('\''); //fix apostrophie itemDescription = itemDescription.split(',-').join('
').split('.,').join('.
');

Hopefully this will be useful for someone.

@bagelbits
Copy link
Collaborator

I think most of these should be fixed from #50, which just contains the fix from this forked PR.

@bagelbits bagelbits reopened this Mar 28, 2019
@bagelbits
Copy link
Collaborator

If you find anymore feel free to reopen the issue.

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

No branches or pull requests

4 participants