How to Access Web APIs using Python Requests and JSON

  Рет қаралды 47,964

TokyoEdtech

TokyoEdtech

Күн бұрын

In this video I'll show you how to quickly and easily access web apis and convert the resulting JSON data into a Python dictionary, pull the relevant information out, and print it. We'll be using TV Maze to get information about various TV shows.
Links:
TV Maze API Info: www.tvmaze.com...
JSON: www.json.org/j...
Code:
import requests
import json
import pprint
url = "api.tvmaze.com/..."
show = input("Please input a show name. ")
params = {"q":show}
response = requests.get(url, params)
if response.status_code == 200:
data = json.loads(response.text)
pprint.pprint(data)
name = data['name']
premiered = data['premiered']
summary = data['summary']
print(f"{name} premiered on {premiered}.")
print(summary)
else:
print(f"Error: {response.status_code}")
NEED HELP?
🆘 Watch this first and then let me know in the comments below: • Help Me Help You
❤️❤️ SHOW SOME LOVE AND SUPPORT THE CHANNEL ❤️❤️
Click Join and Become a Channel Member Today!
Channel members can get preferential comment replies, early access to new content, members only live streams, and access to my private Discord.
❤️ / @tokyoedtech
LINKS
🗄️ GITHUB: github.com/wyn...
💬 Follow me on Twitter: / tokyoedtech
📜 Subscribe to my Newsletter: eepurl.com/dKgM8k
📝 Check out my Blog: christianthomp...
⬇️ Download Geany Editor: www.geany.org
LEARN MORE PYTHON
➡️Space Invaders: • Python Game Programmin...
➡️Snake Game: • Python Game Programmin...
➡️Pong: • Python Game Programmin...
➡️Space War: • Python Game Programmin...
➡️Intro to Python (for Java Coders): • Intro to Python for Ja...
➡️Space Arena - The Ultimate Python Turtle Graphics Game Tutorial: • Ultimate Python Turtle...
LEARN MORE JAVA
➡️Basic Java for Beginners: • Basic Java 1&2: Commen...
➡️Intro to AP Computer Science A: • AP Computer Science Un...
#Python #Tutorial #API #JSON

Пікірлер: 99
@abinsyaseen7298
@abinsyaseen7298 3 жыл бұрын
I learned to make a simple game from the turtle module from you i think a year ago and thats how i started my python journey...and then learnt a lot of stuff like data science and i was thinking to learn about accesing web api s and this video got recommended to me and i had a quick glance on my journey...thanks a lot mate
@TokyoEdTech
@TokyoEdTech 3 жыл бұрын
You're quite welcome - glad I could help. Keep on codin'!
@PLAYCOREE
@PLAYCOREE 8 ай бұрын
Thanks for helping me out, just started this week learning Python as my first language. I started the first time coding with js but i'm really not a very motivated learner when i dont have a goal to reach. For my first learning project i wanted to make a fake donation programm for Twitch streamers using the stream elements api and a simple GUI with customTKinter. Really didnt know why i was having problems with it since i thought it was returning a dictionary. Now i know, appreciate your content even tho this video is 2 years old!
@TokyoEdTech
@TokyoEdTech 8 ай бұрын
It's always good to have a goal, but sometimes you gotta buckle down and do the hard work to make progress. Thanks for the comment and keep on codin'!
@OK-69420
@OK-69420 3 жыл бұрын
I came here from Pong video and just wanted to say that you are the best at explaining coding. Thanks!
@TokyoEdTech
@TokyoEdTech 3 жыл бұрын
Thanks - much appreciated. Keep on codin'!
@lonelypizzaslice4845
@lonelypizzaslice4845 2 жыл бұрын
Tysm for this tutorial! I appreciate how clear and straight-forward it was. I have a project coming up and after some googling, decided it would be quicker to completely relearn HTTP requests in python rather than fight the other language I was using lol.
@TokyoEdTech
@TokyoEdTech 2 жыл бұрын
You are quite welcome. I also decided to use python recently instead of fighting Java. Keep on codin'!
@preciousudo415
@preciousudo415 Жыл бұрын
You have literally saved me from failing my class. The explanation is better than what my professor was trying show in the class. Thank you
@TokyoEdTech
@TokyoEdTech Жыл бұрын
Glad to help - keep on codin'!
@NeoMaduoSaitsoketsa
@NeoMaduoSaitsoketsa 9 ай бұрын
I like the way you explain your code Sir. Makes everything very clear... Thanks... 🎉
@TokyoEdTech
@TokyoEdTech 9 ай бұрын
Thanks - keep on codin'!
@luiscarlostrotta8119
@luiscarlostrotta8119 Жыл бұрын
good afternoon!!! nice to meet you, I love your didactics. I'm from Argentina and I'm not fluent in English, but thanks to Python and tutorials of such quality as this one, I'm doing well. very good explanation, I'm interested in everything about python!!!!, thank you very much, greetings.
@TokyoEdTech
@TokyoEdTech Жыл бұрын
Gracias! Glad to hear it is helpful. Here is a link to my Intro to Python book (pdf). drive.google.com/file/d/1ajYJZLGUaVmNbuG98LnRfHMTzvnZx9el/view?usp=drivesdk Keep on codin'!
@luiscarlostrotta8119
@luiscarlostrotta8119 Жыл бұрын
@@TokyoEdTech Very kind!!!!! Thank you very much!!!!
@rsb7613
@rsb7613 Күн бұрын
Please, help me! I did the same code in the same api and all fields come in my calls only the "summary" that not, comes: Star Trek premiered on 1966-09-08. ['summary'] For any movie In time: I am using python 3.12 and VSCode
@TokyoEdTech
@TokyoEdTech Күн бұрын
@@rsb7613 Can you share the code so I can take a look?
@seadve
@seadve 3 жыл бұрын
very helpful video! btw, you can s also do response.json() to convert it to a dict instead lf using json module
@TokyoEdTech
@TokyoEdTech 3 жыл бұрын
Great tip - thanks for sharing that!
@Butssy
@Butssy 2 жыл бұрын
hi, i have a question, when i do the pprint.pprint, it comes up as an error, and says it is undefinied. is there any reason why this would happen? edit: simple mistake, forgot to import pprint
@TokyoEdTech
@TokyoEdTech 2 жыл бұрын
Glad you caught that...been there, done that!!!
@fx572
@fx572 3 жыл бұрын
I was wondering if I could have your opinion on something: I’ve been using an animation program for a few months now called Source Filmmaker where you do 3D animation on. I wanted to script for some IK rigs so I looked around on Google to find out how to that when I found this article that shows you how to do that. I read it and right off the bat, the guide told me I needed Python for making the scripts and saving them into Source Filmmakers directory. I spent mostly all of today trying to figure out how to use it and I’ve pretty much have come to the conclusion that I’m gonna have to learn Python step by step. What would you suggest I try?
@TokyoEdTech
@TokyoEdTech 3 жыл бұрын
Check out my intro to Python - it'll get you started!
@TheSpekeyMan
@TheSpekeyMan 3 жыл бұрын
Hey man I wanted to ask something "I used ur code to make a game (Snake Game) and also modified it a little bit. ("Can i copyright and publish it to Microsoft Store or The Play Store? ") PLS answer me
@TokyoEdTech
@TokyoEdTech 3 жыл бұрын
Heya - sure thing! Every thing I do is Creative Commons Licensed - please include a shoutout in the game credits. Good luck!
@TheSpekeyMan
@TheSpekeyMan 3 жыл бұрын
U said yas or no? Idk But what is "Creative Commons Licensed?"
@TokyoEdTech
@TokyoEdTech 3 жыл бұрын
@@TheSpekeyMan Yes, go ahead. Please Google Creative Commons.
@TheSpekeyMan
@TheSpekeyMan 3 жыл бұрын
And I also wanted to ask "MUST i shout u out in the credits?" That was my last question. THX for the snake tutorial video man. And NO-OFFENCE asking u the last question. BYE :)
@TokyoEdTech
@TokyoEdTech 3 жыл бұрын
MUST you? No. SHOULD you? Yes. Otherwise, why did you bother asking?
@CloroxBleach-vc1pw
@CloroxBleach-vc1pw Жыл бұрын
thanks, this helped me create a simple program to hopefully get rich in Albion Online
@TokyoEdTech
@TokyoEdTech Жыл бұрын
Get rich or die trying - good luck!
@sand3514
@sand3514 8 ай бұрын
Hello! I have recently started to learn things about APIs (what they are, different kinds of requests, etc) and as ive seen, Postman is used alot by data scientists to send HTTP requests to APIs. What are the pros of using Postman? (As ive seen, it sends a http request just as you showed in the video, the only thing that i can notice is that Postman is more efficient, but what other pros does it have?)
@TokyoEdTech
@TokyoEdTech 8 ай бұрын
Hi! From what I can tell, Postman is a full-featured API system that not only provides APIs, but also allows for testing and troubleshooting. What I showed in this video is the barest example to explain the concept.
@gummies579
@gummies579 3 жыл бұрын
I know a lot of people have been asking but when are you going to continue space arena
@TokyoEdTech
@TokyoEdTech 3 жыл бұрын
I was hoping to get to it this summer, but it is unlikely due to unforeseen circumstances. Sorry.
@stephendoamekpor1671
@stephendoamekpor1671 2 жыл бұрын
This is what I get when I run the code.....need help. Traceback (most recent call last): File "c:\Users\edemd\Documents\DoamPrograms\py4e\practice\workpage.py", line 15, in name = data['name'] TypeError: list indices must be integers or slices, not str
@TokyoEdTech
@TokyoEdTech 2 жыл бұрын
I need to see the code also to help.
@devanshujoshi8393
@devanshujoshi8393 3 жыл бұрын
What is this I didn't understand I subscribed your channel after learning to build games and learnt python , is this something advanced for a python intermediate or beginner
@TokyoEdTech
@TokyoEdTech 3 жыл бұрын
This is probably a bit more advanced - watch the previous video about the requests module then try this one.
@valluriseshapraneeth3469
@valluriseshapraneeth3469 8 ай бұрын
Hi sir, I have a url with API key how can i retrieve the data, You have placed the last part of the URL as parameters. Where can I put the API key
@TokyoEdTech
@TokyoEdTech 8 ай бұрын
Hiya. The API key is usually a parameter as well. You'll have to check the site documentation to figure out how to use it.
@bvladimirpl
@bvladimirpl 2 жыл бұрын
Simple and easy to follow! Thanks TokyoEdtech
@TokyoEdTech
@TokyoEdTech 2 жыл бұрын
You're welcome - keep on codin'!
@乲
@乲 Жыл бұрын
Hey I am getting error- list indices must be integers or slices, not str Can you please help?
@TokyoEdTech
@TokyoEdTech Жыл бұрын
Sure. Paste your code here and I'll take a look.
@乲
@乲 Жыл бұрын
@@TokyoEdTech nvm figured it out thanks for the help
@TokyoEdTech
@TokyoEdTech Жыл бұрын
@@乲 Good to hear - keep on codin'!
@laredoeneko
@laredoeneko 9 ай бұрын
How do you search in the API? imagine search for all the movies/series from the year=2010 for example, in this case the reponse is not unique, how doest python manage it?
@TokyoEdTech
@TokyoEdTech 9 ай бұрын
You'd have to check the API documentation. Then print the result of your query and see the data format and go from there.
@unbreakable7643
@unbreakable7643 3 жыл бұрын
I have a question for you about functions. Can you put a function inside a function? For Example: def hello(): print("hello world") print("hello #2") def IdontKnowanyMore(): print("I dont know anymore") hello()
@TokyoEdTech
@TokyoEdTech 3 жыл бұрын
That's a good question - did you try your code? What happened?
@unbreakable7643
@unbreakable7643 3 жыл бұрын
@@TokyoEdTech not yet I could try it.
@unbreakable7643
@unbreakable7643 3 жыл бұрын
@@TokyoEdTech I just tried it, it worked!
@azghar.suhail
@azghar.suhail 2 жыл бұрын
Thanks for the video. I have an URL in json. How do I make that URL open in browser?
@TokyoEdTech
@TokyoEdTech 2 жыл бұрын
First pull the URL out of the json data Second, follow the directions here: stackoverflow.com/questions/4302027/how-to-open-a-url-in-python#:~:text=just%20open%20the%20python%20interpreter,it%20does%20what%20you%20want.
@trending1360
@trending1360 3 жыл бұрын
sir you teach so well
@TokyoEdTech
@TokyoEdTech 3 жыл бұрын
Thank you, I try.
@kavitham4526
@kavitham4526 3 жыл бұрын
Hi, I learned about python and also some gaming programs which is very helpful for me and also for everyone. I need a help from you as a guide.. Is there any possibility to write a code to convert text to animation video...If it is so, then it will be really helpful for me.
@TokyoEdTech
@TokyoEdTech 3 жыл бұрын
Hiya - I'm sure it's possible, but I'm not sure how to go about that one...gotta study more!
@colwarsstudiobrickfilmandm8580
@colwarsstudiobrickfilmandm8580 3 жыл бұрын
Are you having a creative block? Not mad or anything but I'm just wondering when your next video will be?
@TokyoEdTech
@TokyoEdTech 3 жыл бұрын
Nope. Just a lot of personal stuff going on. Hoping to get me stuff out next month...
@jonathanantfolk7023
@jonathanantfolk7023 3 жыл бұрын
man ive been waiting for a video on this
@TokyoEdTech
@TokyoEdTech 3 жыл бұрын
Glad to hear it - enjoy!
@thech0sen1
@thech0sen1 3 жыл бұрын
KZbin just notified me about this. I am subbed and it ain't sending me notifications :(
@TokyoEdTech
@TokyoEdTech 3 жыл бұрын
KZbin is mysterious like that!
@berkayavclar110
@berkayavclar110 3 жыл бұрын
You are the best and you don't get what you deserve
@TokyoEdTech
@TokyoEdTech 3 жыл бұрын
Thanks - much appreciated!
@thebdceigal
@thebdceigal Жыл бұрын
This was exactly what I was searching for thank you!
@TokyoEdTech
@TokyoEdTech Жыл бұрын
You're welcome. Keep on codin'!
@ayanupadhaya6972
@ayanupadhaya6972 3 жыл бұрын
Which editor you are using?
@TokyoEdTech
@TokyoEdTech 3 жыл бұрын
You’re in luck - I’ve made a video about this exact topic. Enjoy! kzbin.info/www/bejne/apOvXp95hZenm8U
@ayanupadhaya6972
@ayanupadhaya6972 3 жыл бұрын
@@TokyoEdTech I want a help from you. As I program in python I use pip to install packages. Currently using linux mint mate os. I don't know what is the problem whenever I try ton install a package using pip3 it takes 2 or 3 minutes where it would take few seconds in windows 10 to download a package. Any solution?
@siddhartha.01
@siddhartha.01 3 жыл бұрын
Do you know how to scrape Userinfo of Quora user(Without Using Requests-HTML or Selenium)?
@TokyoEdTech
@TokyoEdTech 3 жыл бұрын
Sorry, no. I've used Selenium in the past, but it was a looooong time ago.
@siddhartha.01
@siddhartha.01 3 жыл бұрын
@@TokyoEdTech i hate selinum too that's I don't want to use it😕
@TokyoEdTech
@TokyoEdTech 3 жыл бұрын
Hang in there!
@PlaneteAdos
@PlaneteAdos Жыл бұрын
Good professor ! Thanks a lot !!!
@TokyoEdTech
@TokyoEdTech Жыл бұрын
You're welcome - keep on codin'!
2 жыл бұрын
that was helpful, thank you a lot :)
@TokyoEdTech
@TokyoEdTech 2 жыл бұрын
You are quite welcome - keep on codin'!
@montagetm
@montagetm 3 жыл бұрын
Could you try making Chess? 🤔
@TokyoEdTech
@TokyoEdTech 3 жыл бұрын
It's definitely on my to-do list. I started a text-based version a while ago, but never got back to it. LINK: pastebin.com/4VNcyHru
@diyeyejohson3070
@diyeyejohson3070 2 жыл бұрын
Great video! I love it!
@TokyoEdTech
@TokyoEdTech 2 жыл бұрын
Thank you!
@colwarsstudiobrickfilmandm8580
@colwarsstudiobrickfilmandm8580 3 жыл бұрын
You should start a reddit! That way its easier to help people!
@TokyoEdTech
@TokyoEdTech 3 жыл бұрын
Thanks, but I barely have time to keep up with my channel these days!
@colwarsstudiobrickfilmandm8580
@colwarsstudiobrickfilmandm8580 3 жыл бұрын
@@TokyoEdTech I'm so sorry I didnt think about that!
@TokyoEdTech
@TokyoEdTech 3 жыл бұрын
@@colwarsstudiobrickfilmandm8580 No worries - I'm a relatively small KZbinr and get lots of requests for help. I can't imagine what larger channels have to deal with!
@colwarsstudiobrickfilmandm8580
@colwarsstudiobrickfilmandm8580 3 жыл бұрын
In the olden days of minecraft pe..... mods were made in json! They are now made in c++ (I think)
@thatelguy1530
@thatelguy1530 3 жыл бұрын
Yep they are
@TokyoEdTech
@TokyoEdTech 3 жыл бұрын
Ahh...the olden days!
@berkayavclar110
@berkayavclar110 3 жыл бұрын
can you make formula 1 game in python pleas
@TokyoEdTech
@TokyoEdTech 3 жыл бұрын
What did you have in mind? Do you have a link?
@berkayavclar110
@berkayavclar110 3 жыл бұрын
@@TokyoEdTech Yes i have kzbin.info/www/bejne/rGPRomB_fN-SgLM
@trending1360
@trending1360 3 жыл бұрын
sir plz plz plz make animation python 3 part 7
@TokyoEdTech
@TokyoEdTech 3 жыл бұрын
Not sure what else to the animation video.
@heckergrp
@heckergrp Жыл бұрын
Hey I am getting error- list indices must be integers or slices, not str Can you please help?
@TokyoEdTech
@TokyoEdTech Жыл бұрын
Sure. Paste the code here and the exact error message.
Simple Python Turtle Graphics Game (Part 1)
6:07
TokyoEdtech
Рет қаралды 135 М.
Working With APIs in Python - Pagination and Data Extraction
22:36
John Watson Rooney
Рет қаралды 105 М.
Flipping Robot vs Heavier And Heavier Objects
00:34
Mark Rober
Рет қаралды 46 МЛН
Seja Gentil com os Pequenos Animais 😿
00:20
Los Wagners
Рет қаралды 24 МЛН
А что бы ты сделал? @LimbLossBoss
00:17
История одного вокалиста
Рет қаралды 8 МЛН
How I Turned a Lolipop Into A New One 🤯🍭
00:19
Wian
Рет қаралды 10 МЛН
The Biggest Issues I've Faced Web Scraping (and how to fix them)
15:03
HOW TO: JSON and APIs in PYTHON - A Beginners Look
25:40
John Watson Rooney
Рет қаралды 44 М.
This Is Why Python Data Classes Are Awesome
22:19
ArjanCodes
Рет қаралды 809 М.
Learn JSON in 10 Minutes
12:00
Web Dev Simplified
Рет қаралды 3,2 МЛН
Python for API - Learn how to access any API with Python
25:38
DevOps Journey
Рет қаралды 41 М.
Flipping Robot vs Heavier And Heavier Objects
00:34
Mark Rober
Рет қаралды 46 МЛН