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

change default encoding of API calls to 'utf-8' #663

Open
emileaben opened this issue Mar 11, 2020 · 2 comments
Open

change default encoding of API calls to 'utf-8' #663

emileaben opened this issue Mar 11, 2020 · 2 comments
Assignees
Labels
Milestone

Comments

@emileaben
Copy link

@emileaben emileaben commented Mar 11, 2020

As I've struggled many hours now with the interaction between the
python2 (don't ask, but for this i couldn't switch to python3 ...)
requests library and peeringDB API, I'd like to make the following
suggestion for change.

If I query:
https://www.peeringdb.com/api/ix

The response headers say:
content-type: application/json; charset=iso-8859-1

I think it makes more sense to have the charset be 'utf-8' for the json
output.

The current charset (iso-8859-1) causes python programmers extra steps trying to convert this to unicode. For instance, in the much used python requests library you need
to know and understand this. The standard approach is this:

r_ixlan = requests.get("https://www.peeringdb.com/api/ixlan")
j_ixlan = r_ixlan.json()

to get the json output (but all kinds of hell happens when you try
manipulating for instance the ixp 'name' field that contains non-ascii
code).

What one needs to do to get this right:

   r_ix = requests.get("https://www.peeringdb.com/api/ix")
   # do this differently because ascii/utf-8 etc.
   r_ix.encoding = 'utf-8'
   r_ix_txt = r_ix.text
   j_ix = json.loads( r_ix_txt )
   # ^^---- these 3 lines are hours of effort 

In my case I have the solution now, but I think it will save hours of
pain on people trying to program against peeringDB if you make this change.
Happy to make a twitter poll or somesuch to see if i'm the only one who
had to deal with this.

hope this helps make peeringDB even better!

thanks for providing this service, it's awesome

best regards,
Emile Aben
RIPE NCC

@arnoldnipper arnoldnipper self-assigned this Mar 11, 2020
@arnoldnipper arnoldnipper added this to the 1 Decide milestone Mar 11, 2020
@arnoldnipper

This comment has been minimized.

Copy link
Contributor

@arnoldnipper arnoldnipper commented Mar 11, 2020

@peeringdb/pc makes sense to me, hence +1. But would like to hear the programmer's pov ... @grizz and @vegu

@shane-kerr

This comment has been minimized.

Copy link

@shane-kerr shane-kerr commented Mar 11, 2020

+1

I'm fully in favor of moving everything to UTF-8.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.