Skip to content
Advertisement

Troubles merging two json urls

First of all, I am getting this error. When I try running pip3 install --upgrade json in an attempt to resolve the error, python is unable to find the module. The segment of code I am working with can be found below the error, but some further direction as for the code itself would be appreciated.

Error:

JavaScript

Script:

JavaScript

Advertisement

Answer

json.load expects a file object or something else with a read method. The BeautifulSoup object doesn’t have a method read. You can ask it for any attribute and it will try to find a child tag with that name, i.e. a <read> tag in this case. When it doesn’t find one it returns None which causes the error. Here’s a demo:

JavaScript

Output:

JavaScript

If the URL is returning JSON then you don’t need BeautifulSoup at all because that’s for parsing HTML and XML. Just use json.loads(response.data).

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement