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

Closed
emileaben opened this issue Mar 11, 2020 · 5 comments · Fixed by #751
Closed

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

emileaben opened this issue Mar 11, 2020 · 5 comments · Fixed by #751
Assignees
Labels
enhancement Requires Notice Implementing this ticket requires user be notified Time:Minor Up to 4 hours
Milestone

Comments

@emileaben
Copy link

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
Copy link
Contributor

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

@shane-kerr
Copy link

+1

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

@grizz
Copy link
Member

grizz commented Apr 18, 2020

+1

@grizz grizz added Requires Notice Implementing this ticket requires user be notified Time:Minor Up to 4 hours labels Apr 24, 2020
@koalafil
Copy link

Can we have a Release Note pls?

@arnoldnipper
Copy link
Contributor

Release Note
The output of API calls will change from content-type: application/json; charset=iso-8859-1 to content-type: application/json; charset=utf-8

vegu pushed a commit that referenced this issue Jun 24, 2020
change default encoding of API calls to 'utf-8' #663

See merge request gh/peeringdb/peeringdb!81
@grizz grizz mentioned this issue Jun 24, 2020
grizz added a commit that referenced this issue Jun 24, 2020
* Add pointer from API docs to tutorial #650

* Sorting by clicking table headers should use local-compare #356

* Mark IXP peering LAN as bogon #352

* Add help text to "Add (Facility, Network, Exchange)" tab #669

* Add Looking Glass field to the IX object #672

* Add read-only Superuser #679

* Make spelling of traffic levels consistent #519 (#723)

* Offer 2FA (#290)

* Show "Last Updated" fields on fac, ix, org records (#526)

* Enable sort and reverse sort of IP column in IX display (#72)

* IRR validation not handling unexpected characters gracefully (#712)

* Support alternative direction of writing, e.g. Arabic (#618)

* Undeleting an ixlan with an emtpy IPv4 XOR IPv6 field throws a silly error (#644)

* Changing org while adding net results in 500 #654

* missing delete button for organisations (#121)

* When changing owner of an ix admin GUI borks because of "Ixlan for exchange already exists" #666

* Selection should only present undeleted objects (#664)

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

* Posting https://www.peeringdb.com onto social media doesn't select a good preview image #537

* Revert "Add Looking Glass field to the IX object #672"

This reverts commit 4daf252.

Conflicts:
	peeringdb_server/migrations/0037_ix_looking_glass.py
	peeringdb_server/views.py

* 500 Internal Error when creating IX where prefix already exists elsewhere #718

* Fix graceful restore of soft-deleted objects with translation active (#580)

* Don't return any POC data with status=deleted #569
Hard delete soft-deleted pocs after grace period #566

* django-peeringdb from github@2.0.0.2-beta

Co-authored-by: Stefan Pratter <stefan@20c.com>
@vegu vegu modified the milestones: Next Release, 2.21 Jul 15, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Requires Notice Implementing this ticket requires user be notified Time:Minor Up to 4 hours
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants