dump() missing 1 required positional argument: 'fp' in python json

PythonJsonPython 2.7Python 3.x

Python Problem Overview


I am trying to prettify the json format but i am getting this error:

import requests as tt
from bs4 import BeautifulSoup
import json

get_url=tt.get("https://in.pinterest.com/search/pins/?rs=ac&len=2&q=batman%20motivation&eq=batman%20moti&etslf=5839&term_meta[]=batman%7Cautocomplete%7Cundefined&term_meta[]=motivation%7Cautocomplete%7Cundefined")
soup=BeautifulSoup(get_url.text,"html.parser")

select_css=soup.select("script#jsInit1")[0]
for i in select_css:
    print(json.dump(json.loads(i),indent=4,sort_keys=True))

Basically i want to extract this type of element :

'orig': {'width': 1080, 'url': '', 'height': 1349},

I know i can do this with

select_css.get('orig').get('url')

But i am not sure is this json element is nested element under any element ? That's why i am trying to prettify to get idea.

Python Solutions


Solution 1 - Python

Use json.dumps() instead. json.dump() needs a file object and dump JSON to it.

Solution 2 - Python

It worked when I replaced

json_dump = json.dump(data_set)

by

json_dump = json.dumps(data_set)

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionAaditya UraView Question on Stackoverflow
Solution 1 - PythonHou LuView Answer on Stackoverflow
Solution 2 - Pythonvinod.s.kadamView Answer on Stackoverflow