I'm trying to display content of http request with python, I've tried this
page= requests.request(method="get",url=url, params= parameters)
j_results=json.loads(page.text)
print (page)
But I get this:
ValueError Traceback (most recent call last)
<ipython-input-42-9f7940edb2de> in <module>()
13 page= requests.request(method="get",url=url, params= parameters)
14
---> 15 j_results=json.loads(page.text)
16 print (page.text)
17
C:\Users\sony\Anaconda3\lib\json\__init__.py in loads(s, encoding, cls, object_hook, parse_float, parse_int, parse_constant, object_pairs_hook, **kw)
316 parse_int is None and parse_float is None and
317 parse_constant is None and object_pairs_hook is None and not kw):
--> 318 return _default_decoder.decode(s)
319 if cls is None:
320 cls = JSONDecoder
I'm using Python 3.
Your traceback is showing a different thing than the code you posted.
# Your code snippet
j_results=json.load(page.text)
# Your traceback
j_results=json.load(page)
# You should be using the `loads` function (which loads from a string)
j_result = json.loads(page.text)
Change your code to match what you posted in your snippet. Alternatively, if you know the response is JSON already, you can use
j_result = page.json()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With