Last active
May 10, 2022 00:53
-
-
Save KenoLeon/c237525a81d7c8520cd8e426a9116612 to your computer and use it in GitHub Desktop.
example of using requests in Python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import requests | |
| from requests.structures import CaseInsensitiveDict | |
| # ENDPOINT: | |
| url = "http://colormind.io/api/" | |
| # Request Format | |
| headers = CaseInsensitiveDict() | |
| headers["Content-Type"] = "application/json" | |
| data = '{"model":"default"}' | |
| # Request: | |
| resp = requests.post(url, headers=headers, data=data) | |
| if resp.status_code == 200: | |
| print(resp.json()) | |
| else: | |
| print(resp.status_code) | |
| # >> | |
| # {'result': [[252, 236, 177], | |
| # [225, 195, 67], | |
| # [248, 65, 32], | |
| # [145, 43, 75], | |
| # [68, 43, 87]]} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment