below python code
r = requests.get("https://www.googleapis.com/youtube/v3/search?part=snippet&maxresults=50&channelid="+channelid+"&order=date&key="+developer_key) json = r.json() items = json.get("items") videos = [] x in items: title = x["snippet"]["title"] videoid = x["id"]["videoid"] channeltitle = x["snippet"]["channeltitle"] cam_thumbnails = x["snippet"]["thumbnails"]["medium"]["url"] publishedat = x["snippet"]["publishedat"] data = { "title" : title, "videoid" : videoid, "channeltitle" : channeltitle, "cam_thumbnails" : cam_thumbnails, "publishedat" : publishedat, } videos.append(data) print json.dumps(videos) # code cause problem
i inserted 'dict' 'list' , called json.dumps() but, error arised error messege 'dict' object has no attribute 'dumps'
what problem?, , how can solve problem?
previously, must have imported json module, writing import json
, creates variable in namespace, name json
. then, json = r.json()
, ie. assign new reference name json
, doesn't represents module json anymore, but, instead, result of r.json()
method. thus, can't use anymore json module using syntax json.function()
, because json result of r.json(). resolve problem, must change name of variable named json
in example, to, example, json_dict
or else.
Comments
Post a Comment