Skip to content
This repository

Update the advanced doc to use the r.json method #1085

Merged
merged 1 commit into from over 1 year ago

5 participants

Thomas Grainger Cory Benfield Ian Cordasco Kenneth Reitz
Thomas Grainger

No description provided.

Cory Benfield
Collaborator

Awesome. I'm +1 on this. The broken tests aren't your fault. =D

Ian Cordasco
Collaborator

+1 as well

sprt commented on the diff
docs/user/advanced.rst
@@ -313,17 +313,12 @@ out what type of content it is. Do this like so::
313 313 ...
314 314 application/json; charset=utf-8
315 315
316   -So, GitHub returns JSON. That's great, we can use the JSON module to turn it
317   -into Python objects. Because GitHub returned UTF-8, we should use the
318   -``r.text`` method, not the ``r.content`` method. ``r.content`` returns a
319   -bytestring, while ``r.text`` returns a Unicode-encoded string. I have no plans
320   -to perform byte-manipulation on this response, so I want any Unicode code
321   -points encoded.
  316 +So, GitHub returns JSON. That's great, we can use the ``r.json`` method to
3
sprt added a note

Typo: r.json should be r.json()

Actually r.json is the method. r.json() is an invocation.

It seems that throughout the documentation the invocation and the method are used interchangeably.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Ian Cordasco
Collaborator

Heh, good catch. Would have been good if @Lukasa or I had actually looked at the PR. ;)

Kenneth Reitz
Owner

Thanks!

Kenneth Reitz kennethreitz merged commit 47fe258 into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

Jan 04, 2013
Thomas Grainger graingert Update the advanced doc to use the r.json method 7687746
This page is out of date. Refresh to see the latest.

Showing 1 changed file with 5 additions and 10 deletions. Show diff stats Hide diff stats

  1. +5 10 docs/user/advanced.rst
15 docs/user/advanced.rst
Source Rendered
@@ -313,17 +313,12 @@ out what type of content it is. Do this like so::
313 313 ...
314 314 application/json; charset=utf-8
315 315
316   -So, GitHub returns JSON. That's great, we can use the JSON module to turn it
317   -into Python objects. Because GitHub returned UTF-8, we should use the
318   -``r.text`` method, not the ``r.content`` method. ``r.content`` returns a
319   -bytestring, while ``r.text`` returns a Unicode-encoded string. I have no plans
320   -to perform byte-manipulation on this response, so I want any Unicode code
321   -points encoded.
  316 +So, GitHub returns JSON. That's great, we can use the ``r.json`` method to
  317 +parse it into Python objects.
322 318
323 319 ::
324 320
325   - >>> import json
326   - >>> commit_data = json.loads(r.text)
  321 + >>> commit_data = r.json()
327 322 >>> print commit_data.keys()
328 323 [u'committer', u'author', u'url', u'tree', u'sha', u'parents', u'message']
329 324 >>> print commit_data[u'committer']
@@ -380,7 +375,7 @@ Cool, we have three comments. Let's take a look at the last of them.
380 375 >>> r = requests.get(r.url + u'/comments')
381 376 >>> r.status_code
382 377 200
383   - >>> comments = json.loads(r.text)
  378 + >>> comments = r.json()
384 379 >>> print comments[0].keys()
385 380 [u'body', u'url', u'created_at', u'updated_at', u'user', u'id']
386 381 >>> print comments[2][u'body']
@@ -417,7 +412,7 @@ the very common Basic Auth.
417 412 >>> r = requests.post(url=url, data=body, auth=auth)
418 413 >>> r.status_code
419 414 201
420   - >>> content = json.loads(r.text)
  415 + >>> content = r.json()
421 416 >>> print content[u'body']
422 417 Sounds great! I'll get right on it.
423 418

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.