 Okay, welcome to Python request module just the basics with Tokyo EdTech That is me where we get a quick shout out to all of my channel members special Thanks to Kevin Paul for making it to six months of support Cannot do it without you. Thanks to everybody else who has subscribed commented thumbs up whatever you call it liked and Yeah, join his members. Thanks so much everybody. Anyway today's lesson is the Python requests module and I'm gonna do you know too too much with it But I'm gonna help you get started with and show you kind of how it works at least a little bit of it and The request module is something that usually at least in my case it did not come with Python so I actually had to install it afterwards from pi pi and if you don't have the request module the way to install it is to open up the terminal and Depending on the way your computer is set up you would type pip install requests And notice it's requests not singular or not one request. Let's try and see what happens a pip not found So I'm gonna go ahead and try pip three on my computer and you can see okay That's doing a little bit more says requirement already satisfied because I have already installed this Previous to making the video so you should see some things there. You might also if you're on Linux You might have to put pseudo I'm not sure what the windows equivalent to that would be but you know Check that out for your operating system. So assuming that this is installed What it lets us do is it lets us act, you know contact web sites send information back and forth Etc. Etc. So what I'm gonna do today is I'm gonna show you basically how to do just that Now in preparation for that I've set up a very simple Python script on my web server And I'll show you up with the address in here later when we do the code But there's just a very simple file and it's called dictionary dot py now if I am Trying to send information to this this particular script takes one argument and it is word and Equals and I'm gonna do Apple Okay, that lower case. I'm not sure if it matters or not But what this will do is it will send to my web server this dictionary dot Py file in my server and I'm sending English so Apple and it's returning Japanese so Ringo Like Ringo star is the Japanese word for Apple and so I'm not sure what all other words I don't have that many words in there. It's just a few. I think I have bear and a kuma is bear I forget what C word I did D. Of course, I did dog You know, so just a few Japanese words are listed in this file I should do more but this is just a demonstration So here I'm using a web server All right, excuse me a web browser and the question mark and word equals dog. So my Python script is looking for Word and the value of word in this case is dog And it's as you can see it is returning the Japanese equivalent written in English characters, unfortunately But that'll make life easy. So let's go ahead and do that in code So what I'm gonna do is I'm gonna go ahead and do import Requests and notice it's requests not a singular requests and then what I need to do is I'm gonna go ahead and say what my URL is and my URL in this case is HTTPS colon slash-slash Christian Thompson dot com slash Dictionary dot P y and that is that well what I could do I could do it like this I could do question word equals Apple And I could add it just like that and then what we'll do is I'll say a response equals Request I think it's get Actually, I should have looked this up before I did this, but let's try it. Well, it seems like it's right URL Now this response is a response object. It's not like it's not a string. It's not text So I can print out a couple things. I can say print I'm doing f string here quote and I'll say You know, what's I called a response code? I think it's called response code And quote you'll say here response dot Sponses code that's our response code. What is it? Well, that's why I open this up It is It's in here somewhere I'll put this link in the things below Read the docs. Let's go check out the docs Status code. That's what it is status code and it's response dot status code and 200 means all good 404 means file not found 500 something is usually a server error, etc, etc But what we want is we want to say we want to see the actual response. So the Japanese translation So that's going to be a response dot text So I'm going to save it and watch down here. I'm going to go ahead and run it You can see that you can see there was a little bit of a delay And that's because it was actually contacting my remote web server Christian Thompson comm etc, etc And the response the status code was 200, which means no problem. I didn't need to print that I was just pretty to show you that that does exist and then the text is what it actually printed back to me So I'm able to send information and then I'm able to return it just like that now We don't want to do this every single time, especially if we want to send more than one parameter, so what I can do is I can make a dictionary Params doesn't have to be called params. I could have called it P But parameters or parms params. This is what's been recommended and it is word and Apple this is just a standard dictionary notice. There's no spaces or anything and then I need to add here params So that saves me from having to put question blah blah blah equals and encoding it a certain way Let's go ahead and test it. Just make sure it's working Oops invalid syntax. What did I do? I got two equal signs? And let's try that again And again, you see that little bit of a delay where it's trying to get the information Now I'm gonna go ahead and change that to a try a different one bear. I think we mentioned earlier Again, a little bit of a delay and then there is kuma, which is the Japanese word for bear Now if I didn't send anything, let's see what happens there. I'm kind of curious Okay, so status code 200, but there was just nothing was sent because it didn't know what that particular word was And I think that's about it. I mean, I don't know what else to tell you about this Feel free to use this URL in testing your code Now you might want to do something like, you know, you know, for example word equals, you know input, you know What word? You know, would you like? Translate You know, for example, and then in here I would put Word because that's the variable Let's see if that works. I'm not sure if I haven't tested it, but let's try it out Okay, what word would you like to translate? Let's go ahead and do Apple since we know that works and You can see I entered Apple and it gave me Ringo back. I didn't go. I should say to pronounce it correctly I'll just try it again And let's do Let's do a word that's not in there I don't think cats in there because I'm a dog person and you can see it returns None, this is what I told it to return if the word didn't exist. So that's on the server side So that is basically that Now using this request module you could pull in, you know The HTML from any web page that you wanted to which is pretty cool. So yeah, so that's it It's very short The code is only a few lines long and it's it's quite a useful and powerful Module, so I hope you find some you know good uses for this White hat not black hat of hacking. Okay. Take care everybody. Have a good one. Bye. Bye