0

I am attempting to access the random color palette option from this API using Python and requests http://colormind.io/api-access/

The API's instructions do not mention how to access with requests in Python. I have tried several things and receive this message in Terminal when attempting to print the JSON.

bound method Response.json of <Response [200]>>

my code :

import requests as req
import json

def query():
    url = 'http://colormind.io/api/'
    response = req.get(url, data={"model":"default"}
    )
    print(response.json)


query()

when attempting to load the JSON or print JSON text it appears like it is an empty dictionary or list

what's happening here?

fizzzypop
  • 3
  • 1
  • Hi fizzy, welcome to stack overflow. It seems you are making a bad call. You likely will want to read more on how to send that API a correct call. I would recommend running through an example like this one first, [Find Current Weather API](https://www.geeksforgeeks.org/python-find-current-weather-of-any-city-using-openweathermap-api/) Also, following this [example](https://stackoverflow.com/questions/16877422/whats-the-best-way-to-parse-a-json-response-from-the-requests-library) that URL is not returning valid JSON, instead its returning a `500 Internal Server Error` – Zack Tarr Apr 03 '20 at 05:05
  • Does this answer your question? [What's the best way to parse a JSON response from the requests library?](https://stackoverflow.com/questions/16877422/whats-the-best-way-to-parse-a-json-response-from-the-requests-library) – Zack Tarr Apr 03 '20 at 05:08

1 Answers1

0

I used following code in terminal and received results.

import requests
data = '{"model":"default"}'
response = requests.post('http://colormind.io/api/', data=data)
response.json()

{'result': [[71, 94, 97], [109, 152, 137], [183, 213, 193], [243, 239, 204], [240, 153, 122]]}
Jaskaran Singh
  • 421
  • 2
  • 12