简体   繁体   中英

Issues using json.load

I am trying to print a list of commit messages from a git repo using python. The code I am using so far is:

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

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 TypeError: expected string or buffer . What am I doing wrong here? Any pointers would be really appreciated. thanks

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

Use json.load to get a dict from file-like objects and json.loads with strings.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM