#๐Ÿ”’ json read error

22 messages ยท Page 1 of 1 (latest)

uncut owl
#

import requests
import json

isbn = str(9781626863910)

r = requests.get("https://www.googleapis.com/books/v1/volumes?q=isbn:" + isbn)
l = r.json()

print(json.load(r.text))

trying to figure this one out kinda a noob here tbh, still learning this stuff

im on W11 laptop, fresh install, vs code, python from microsoft store??(idk if thats right tbh but it seems to work). code is below the google api just exports a simple json and the str is there cuz im testing this out in a differnt file so i can mess with it easier outside my main one i just dont know why its not working

import requests
import json

isbn = str(9781626863910)

r = requests.get("https://www.googleapis.com/books/v1/volumes?q=isbn:" + isbn)
l = r.json()

print(json.load(r.text))

dapper zincBOT
#

@uncut owl

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

uncut owl
#

i did cross post this in reddit so if i get a solution there ill post it here as well

delicate kernel
#

what exactly is the problem? Is there an error message?

uncut owl
#

sorry the top bit is the error that vs code gives me

delicate kernel
#

er, the top bit of what?

uncut owl
#

Traceback (most recent call last):
File "c:\Users\User\Downloads\bookshelf-main\bookshelf-main\testing isbn.py", line 9, in <module>
print(json.load(r.text))
^^^^^^^^^^^^^^^^^
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.12_3.12.1264.0_x64__qbz5n2kfra8p0\Lib\json_init_.py", line 293, in load
return loads(fp.read(),
^^^^^^^
AttributeError: 'str' object has no attribute 'read'

#

ill just re post

#

i dont have a line 293 i just idk

#

think i copy pasted wrong mb

delicate kernel
#
import requests

response = requests.get(
    "https://www.googleapis.com/books/v1/volumes?q=isbn:9781626863910"
)
print(response.json())
``` works fine
#

no need to call json.load

#

in any case, json.load wants a file, not a string. You can try json.loads, note the trailing s

opaque sky
#

when you get the request back and r.json() is already a dictionary

delicate kernel
#

[firefox renders json nicely; who knew]

uncut owl
#

yeah okay

#

still a noob ill see if i can get that working

#

would ya look at that it works man im am just slow tonight thanks for the help ๐Ÿ‘

delicate kernel
#

๐Ÿ’

dapper zincBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.

#

๐Ÿ”’ json read error