1 00:00:05,330 --> 00:00:07,190 Making requests. 2 00:00:08,570 --> 00:00:09,380 Hello, everyone. 3 00:00:09,410 --> 00:00:16,220 Today, we're going to talk about requests and basically the requests allow you to send a request to 4 00:00:16,230 --> 00:00:25,250 HTP server and get responses and messages sent by the server when answering your request. 5 00:00:25,640 --> 00:00:33,200 Obviously, we have the request package available in item so we can actually use it in order to assess 6 00:00:33,200 --> 00:00:34,220 this requests. 7 00:00:35,570 --> 00:00:40,520 Actually go to the Web page of this package. 8 00:00:40,520 --> 00:00:45,650 So you can see here that there the request and the request package. 9 00:00:45,830 --> 00:00:53,120 And from that page, you can simply learn how to use it on Dock's dot python dash requests dot org muster. 10 00:00:53,450 --> 00:00:56,330 And here's everything that you need to know about requests. 11 00:00:56,570 --> 00:01:02,370 And you can follow these links to see the different functionalities of that library. 12 00:01:02,930 --> 00:01:06,970 But anyways, today we're going to do some exact examples, obviously. 13 00:01:07,490 --> 00:01:13,610 First of all, what you need to do if you don't have it installed yet, let me go out of here. 14 00:01:13,620 --> 00:01:20,720 You need to install it by writing pipe to install recall as. 15 00:01:22,560 --> 00:01:26,370 OK, and the ones who do it, this will be installed in your computer. 16 00:01:26,640 --> 00:01:31,320 I don't get the installation because my requirements are already satisfied. 17 00:01:31,560 --> 00:01:34,430 All the package is already installed in my computer. 18 00:01:35,130 --> 00:01:42,530 So the requests library pretty much automates and simplifies the tasks we were doing already. 19 00:01:42,540 --> 00:01:44,190 And I will show you how this is done. 20 00:01:44,580 --> 00:01:51,390 The main thing that we're going to use here is the get the requests functionality. 21 00:01:51,420 --> 00:01:53,010 So here's how it works. 22 00:01:53,310 --> 00:01:54,960 Let's it python. 23 00:01:56,490 --> 00:02:01,270 And here I would type import requests. 24 00:02:01,560 --> 00:02:02,030 OK. 25 00:02:02,470 --> 00:02:10,380 And that's right, response equals requests and don't get. 26 00:02:11,630 --> 00:02:18,410 OK, so now we're getting a request and let's use here give help, so I'll write HTP 27 00:02:20,780 --> 00:02:21,470 and then. 28 00:02:23,660 --> 00:02:27,550 W w w dot good hope. 29 00:02:29,550 --> 00:02:30,140 Dot com. 30 00:02:30,990 --> 00:02:37,030 OK, and here's how we're going to get the request from the GitHub dot com. 31 00:02:37,530 --> 00:02:46,230 So now we did a request to GitHub dot com and the response of this request is in the response, the 32 00:02:46,230 --> 00:02:46,970 message here. 33 00:02:47,220 --> 00:02:52,560 So we collect the answer from Kitco in the response so far. 34 00:02:52,560 --> 00:02:54,810 Right, the terrorists phones. 35 00:02:56,640 --> 00:03:03,630 You see that our response is 200, which means that the data was successfully or the connection with 36 00:03:03,630 --> 00:03:05,790 GitHub was successful completed. 37 00:03:05,990 --> 00:03:14,310 And if you want to see this and work your way, you can see the right response dot status code and you 38 00:03:14,310 --> 00:03:15,540 just get 200. 39 00:03:17,200 --> 00:03:21,850 You can also do a response and thought reason. 40 00:03:23,850 --> 00:03:30,050 And you will get OK, which means that basically everything is OK, or you can simply do response that 41 00:03:30,840 --> 00:03:38,650 you rld and you can see the euro that was highest, which is the get the dot com and you can also do 42 00:03:38,670 --> 00:03:39,540 response. 43 00:03:40,810 --> 00:03:41,450 That's. 44 00:03:42,920 --> 00:03:43,730 Heather's. 45 00:03:44,680 --> 00:03:55,960 And then you can do content dash pie, OK, and you can get the content type, which, as you remember, 46 00:03:55,960 --> 00:03:58,400 is basically the type of the pager to assist. 47 00:03:58,660 --> 00:04:05,230 So it's text slash HTML extra waste text and voice e-mail the same time. 48 00:04:05,470 --> 00:04:12,090 This is just because Hotmail is simply a text file with a code that is in HTML format. 49 00:04:12,130 --> 00:04:16,950 So this demo format is the ones that are the browsers are reading. 50 00:04:17,290 --> 00:04:24,460 So to assess the header properties here, you can simply do a response, not request. 51 00:04:26,150 --> 00:04:34,460 Not Heather's, OK, and once you do that, you can see that the user agent is python slash request. 52 00:04:34,510 --> 00:04:41,780 So this what we use to assess it, then acceptance and coding is cheesy and deflate. 53 00:04:42,230 --> 00:04:50,200 And then we are getting the accept and the connection keys and you can see their responses as well. 54 00:04:51,780 --> 00:05:01,440 So let's finally write response and dot text in order to view the response in a different way, because 55 00:05:01,440 --> 00:05:03,980 you can basically look at it in many ways. 56 00:05:04,500 --> 00:05:11,790 So this is the way that you look at us as a text and you can see how long is the text actually OK, 57 00:05:12,030 --> 00:05:14,430 because it's not always the computer. 58 00:05:15,810 --> 00:05:19,680 Read languages are easy to be understood by humans. 59 00:05:19,710 --> 00:05:28,020 So this is how our response looks as the text actually very, very long one, a lot of lines of code. 60 00:05:28,380 --> 00:05:37,320 But anyways, this was the way, guys, that you can basically work with curios, assess them and check 61 00:05:37,320 --> 00:05:39,180 the different properties of theirs. 62 00:05:39,600 --> 00:05:43,410 That said, thank you very much for watching and I will see you in the next video.