На самом деле вы звоните API
неправильно. во-первых, вам нужно использовать data=
или json=
в зависимости от типа контента, который вы отправляете на API
, если он form-data
или JSON
.
Во-вторых: movie
недействительно value
, потому что его нужно заключить в "movie"
<двойные кавычки. </p>
Ниже вы должны правильно назвать API
:
import requests
import json
data = {
"q": "movie",
"type": "movie",
"limit": "5"
}
def main(url):
r = requests.get(url, json=data).json()
print(r)
#print(r.keys()) # to see the keys as it's now a JSON dict.
dumper = json.dumps(r, indent=4)
# print(dumper) #to see it in nice formatted tree.
main("https://tastedive.com/api/similar")
Выход:
{'Similar': {'Info': [{'Name': '!!!', 'Type': 'music'}], 'Results': [{'Name': 'Meeting Of Important People', 'Type': 'music'}, {'Name': 'Soldout', 'Type': 'music'}, {'Name': 'La Tour Montparnasse Infernale', 'Type': 'movie'}, {'Name': 'Young & Sick', 'Type': 'music'}, {'Name': 'The Vanity Project', 'Type': 'music'}, {'Name': 'Tyler Bryant & The Shakedown', 'Type': 'music'}, {'Name': 'Thirsty Fish', 'Type': 'music'}, {'Name': 'Sombear', 'Type': 'music'}, {'Name': 'The High Court', 'Type': 'music'}, {'Name': 'Better Luck Next Time', 'Type': 'music'}, {'Name': 'Stars Of Track And Field',
'Type': 'music'}, {'Name': 'Beachwood Sparks', 'Type': 'music'}, {'Name':
'Tinted Windows', 'Type': 'music'}, {'Name': 'Promise Of Redemption', 'Type': 'music'}, {'Name': 'The Music', 'Type': 'music'}, {'Name': 'Pretty Girls Make Graves', 'Type': 'music'}, {'Name': 'Zach Gill', 'Type': 'music'}, {'Name': 'Chappo', 'Type': 'music'}, {'Name': 'Kisses', 'Type': 'music'}, {'Name': 'Jarle Bernhoft', 'Type': 'music'}]}}
А для dumper
:
{
"Similar": {
"Info": [
{
"Name": "!!!",
"Type": "music"
}
],
"Results": [
{
"Name": "Meeting Of Important People",
"Type": "music"
},
{
"Name": "Soldout",
"Type": "music"
},
{
"Name": "La Tour Montparnasse Infernale",
"Type": "movie"
},
{
"Name": "Young & Sick",
"Type": "music"
},
{
"Name": "The Vanity Project",
"Type": "music"
},
{
"Name": "Tyler Bryant & The Shakedown",
"Type": "music"
},
{
"Name": "Thirsty Fish",
"Type": "music"
},
{
"Name": "Sombear",
"Type": "music"
},
{
"Name": "The High Court",
"Type": "music"
},
{
"Name": "Better Luck Next Time",
"Type": "music"
},
{
"Name": "Stars Of Track And Field",
"Type": "music"
},
{
"Name": "Beachwood Sparks",
"Type": "music"
},
{
"Name": "Tinted Windows",
"Type": "music"
},
{
"Name": "Promise Of Redemption",
"Type": "music"
},
{
"Name": "The Music",
"Type": "music"
},
{
"Name": "Pretty Girls Make Graves",
"Type": "music"
},
{
"Name": "Zach Gill",
"Type": "music"
},
{
"Name": "Chappo",
"Type": "music"
},
{
"Name": "Kisses",
"Type": "music"
},
{
"Name": "Jarle Bernhoft",
"Type": "music"
}
]
}
}