Issues using json.load
<p>I am trying to print a list of commit messages from a git repo using python. The code I am using so far is:</p>

<pre><code>import requests, json, pprint


password = "password"
user = "user"
r = requests.get("https://api.github.com/repos/MyProduct/ios-app/commits", auth=(user, password))
j = json.load(r.json())

jsonData = j["data"]
for item in jsonData:
    message = item.get("message")
    print message
</code></pre>

<p>I'm not totally sure what I should be doing here. After doing the HTTP request is it correct that I need to create a JSON and then convert it to a python object? Currently I'm getting the error <code>TypeError: expected string or buffer</code>. What am I doing wrong here? Any pointers would be really appreciated. thanks</p>

<p>The <code>.json()</code> method on requests object already return a proper dict. No need to parse it. So just do <code>j = r.json()</code>.</p>

<p>Use <code>json.load</code> to get a dict from <a href="https://docs.python.org/3/glossary.html#term-file-like-object" rel="nofollow">file-like objects</a> and <code>json.loads</code> with strings.</p>

python json