1 00:00:04,670 --> 00:00:08,520 HTP authentication, hello, everyone. 2 00:00:08,540 --> 00:00:14,000 Today, we're going to try it out, some of the authentication mechanisms that we're talking in the 3 00:00:14,000 --> 00:00:19,380 previous lecture and you can see here that they have the terminal open as well. 4 00:00:19,380 --> 00:00:23,620 Was the feature open in the back? 5 00:00:23,870 --> 00:00:27,060 So we're actually now going to work with a pie chart. 6 00:00:27,080 --> 00:00:33,050 And here I'm going to create a new file and let's select the new file. 7 00:00:33,050 --> 00:00:39,470 And I will say Biasi out for basic authentication. 8 00:00:40,990 --> 00:00:51,460 And let's write our code now, so I'll write to assess the part of the user bill even before Environment 9 00:00:52,660 --> 00:01:08,100 Python three, and then let's import requests and then from requests dot out import HTP. 10 00:01:09,460 --> 00:01:18,070 And here, since we're doing the basic authentication to import basic out and list right now, requests 11 00:01:18,400 --> 00:01:24,120 that I get and here will get the euro in the parameters. 12 00:01:24,490 --> 00:01:28,710 So, OK, let's work again with the GitHub dot com. 13 00:01:29,080 --> 00:01:37,620 So do HTP s and who else is the GitHub user login page. 14 00:01:37,630 --> 00:01:52,150 So it is api api dot get from dot com user and then lets other authentication creators write out. 15 00:01:53,740 --> 00:01:59,360 Equals to A.P. basic content education. 16 00:01:59,380 --> 00:02:05,200 And here I'll write you yuzu and then I will write password. 17 00:02:05,950 --> 00:02:10,340 Now let's create our response from the server. 18 00:02:10,600 --> 00:02:13,960 So response equals requests. 19 00:02:15,160 --> 00:02:18,520 Dot, get in in the brackets. 20 00:02:18,820 --> 00:02:26,650 Let's write HTP s and I'll write a pie dot get up. 21 00:02:26,680 --> 00:02:29,560 Dot com slash. 22 00:02:31,560 --> 00:02:32,010 User. 23 00:02:32,940 --> 00:02:44,070 OK, so the same thing, and then they'll write out your user commo password that said, OK, we're 24 00:02:44,070 --> 00:02:45,040 ready here, guys. 25 00:02:45,630 --> 00:02:51,630 And after that, let's do the print statements or print and let's. 26 00:02:51,630 --> 00:02:52,320 Right here. 27 00:02:54,520 --> 00:02:55,460 Response. 28 00:02:57,240 --> 00:03:08,910 Not status cold, so first of all, I'd like to see the status quo, plus let's create a string is Tara 29 00:03:09,570 --> 00:03:13,230 Response Dog's status. 30 00:03:14,160 --> 00:03:22,710 OK, so here obviously we're going to print what is our status code and then let's write if response 31 00:03:22,980 --> 00:03:31,630 thought status code is equal to 200 or if everything is accepted, then we would like to print and dot 32 00:03:31,650 --> 00:03:35,040 the log in a successful. 33 00:03:36,950 --> 00:03:37,490 OK. 34 00:03:39,920 --> 00:03:46,820 And plus, response dot text and also while other responses. 35 00:03:49,070 --> 00:03:58,040 OK, so let's run this call now and see if it's going to work, so let's do it was here and let's see, 36 00:03:58,920 --> 00:04:05,090 there we go, Python and then Beyaz authentication. 37 00:04:06,240 --> 00:04:10,060 So let's run this file and here we get an error. 38 00:04:10,070 --> 00:04:12,460 So let me check it out. 39 00:04:12,470 --> 00:04:13,510 Is not defined. 40 00:04:13,940 --> 00:04:14,510 Let's see. 41 00:04:15,040 --> 00:04:15,460 Yes. 42 00:04:15,470 --> 00:04:17,600 So here I Friday the course. 43 00:04:18,410 --> 00:04:19,950 So maybe this was the issue. 44 00:04:20,690 --> 00:04:21,230 Yes. 45 00:04:21,600 --> 00:04:28,040 That's from the quote once again and see if it's going to work so you can see that the response status 46 00:04:28,340 --> 00:04:29,660 is 431. 47 00:04:30,170 --> 00:04:37,130 And what that means guys, is that our authentication is not being accepted. 48 00:04:37,280 --> 00:04:37,630 All right. 49 00:04:37,910 --> 00:04:40,600 So our login is not successful here. 50 00:04:41,030 --> 00:04:46,400 And this is the code that you usually see when you couldn't login in that case. 51 00:04:46,830 --> 00:04:49,010 So our code works, which is good. 52 00:04:49,700 --> 00:04:53,670 So this is how you do the basic authentication and this is what gets returned. 53 00:04:54,050 --> 00:04:58,340 Let's now try to do the Tigist authentication. 54 00:04:58,790 --> 00:05:05,570 So let's do Python to go into python mode and I'll import. 55 00:05:07,750 --> 00:05:08,830 Requests. 56 00:05:10,350 --> 00:05:10,870 OK. 57 00:05:11,400 --> 00:05:24,100 And then from requests not out here, we'll import HTP Digest out. 58 00:05:25,020 --> 00:05:32,630 OK, so this package as it exists, is so important, important. 59 00:05:33,000 --> 00:05:35,190 So there's no response. 60 00:05:36,610 --> 00:05:42,480 Response equals request not get. 61 00:05:45,790 --> 00:05:47,560 Protected euro. 62 00:05:50,530 --> 00:06:03,000 Cuomo out equals h t t p they just authentication and here we can write user password. 63 00:06:03,370 --> 00:06:03,720 OK. 64 00:06:05,200 --> 00:06:08,500 Let's bring in our bracket here. 65 00:06:08,530 --> 00:06:12,400 We've got an error so the name requests not defined. 66 00:06:12,430 --> 00:06:21,820 OK, so we need to import the requests instead of requests so requests don't get then instead of the 67 00:06:21,820 --> 00:06:28,330 protected area, let's write to the GitHub login page so you can see I guess it doesn't work with the 68 00:06:28,330 --> 00:06:31,630 API GitHub dot com user that we use previously. 69 00:06:31,900 --> 00:06:37,810 And for that reason, we need to use another website because obviously this one doesn't support they 70 00:06:37,810 --> 00:06:39,010 just authentication. 71 00:06:39,400 --> 00:06:45,820 And for that reason I use this one htp binn dot org. 72 00:06:45,940 --> 00:06:49,720 They just authentication, authentication user pass. 73 00:06:50,110 --> 00:06:54,670 And from that website you can actually opt to the out indication. 74 00:06:55,810 --> 00:07:03,340 And the only thing I need to do is to do instead of basically they just authentication. 75 00:07:03,520 --> 00:07:08,770 And when they run it, you can see that the input is accepted enough to response. 76 00:07:09,530 --> 00:07:12,010 You can see that we're talking to the website. 77 00:07:12,310 --> 00:07:15,870 However, we're able to send request to it. 78 00:07:16,750 --> 00:07:27,190 Let's now try doing this from a script so I will create a Python file here and it will be called Digest 79 00:07:27,940 --> 00:07:29,170 Authentication. 80 00:07:29,440 --> 00:07:37,450 OK, and let's write user hoobin EMV. 81 00:07:39,600 --> 00:07:43,110 Python three in the let's import. 82 00:07:45,490 --> 00:07:57,970 Requests and then I withdraw from requests, not authentication import, they just authentication this 83 00:07:57,970 --> 00:07:58,290 time. 84 00:07:58,690 --> 00:08:12,100 So let's write Eurail equals to h h t t p h t t p bin dot org. 85 00:08:12,580 --> 00:08:13,110 And then. 86 00:08:13,130 --> 00:08:13,750 That's right. 87 00:08:14,500 --> 00:08:15,490 They just. 88 00:08:17,540 --> 00:08:18,850 Dush out. 89 00:08:20,650 --> 00:08:24,670 Then authentication user. 90 00:08:26,130 --> 00:08:26,670 Plus. 91 00:08:28,690 --> 00:08:31,580 But that said, there's a little bit closer. 92 00:08:33,550 --> 00:08:46,480 OK, and then let's read the response response, of course, to request not get and then we want to 93 00:08:46,480 --> 00:08:54,360 get the you are Al, OK, and then I'll write out EQUASS HTP. 94 00:08:54,390 --> 00:08:55,900 They just authentication. 95 00:08:56,350 --> 00:08:58,960 And here I write user. 96 00:09:01,090 --> 00:09:15,070 And then password, that's it, and then let's forget print and so let's print response, not status 97 00:09:15,730 --> 00:09:19,470 codes to us is. 98 00:09:21,250 --> 00:09:27,240 And then I will do a response thought status code, which is what we're going to show here. 99 00:09:27,760 --> 00:09:40,090 And then if the response, not status code, is equal to 200, then you say so we'll print. 100 00:09:41,910 --> 00:09:53,040 OK, being successful, OK, and I will outhere s t r. 101 00:09:55,060 --> 00:09:58,920 Response dogs chase some. 102 00:10:00,360 --> 00:10:01,270 And that's it. 103 00:10:01,440 --> 00:10:10,980 So if we log into the website, then we will display the response that Jason so we will actually say 104 00:10:10,980 --> 00:10:14,440 that Logan is successful and will display the creditors. 105 00:10:14,940 --> 00:10:20,350 So let's save that and let's see if the coach is going to be receptive. 106 00:10:20,550 --> 00:10:30,060 So I will go out to the Python mold like this and illustrate airways so you can see that now we have. 107 00:10:31,540 --> 00:10:41,320 That they just authentications right here, so I will to fight them, they just authentication PVA and 108 00:10:41,320 --> 00:10:44,020 OK, I can get that we are getting an error here. 109 00:10:44,530 --> 00:10:48,180 So let's see, what could it be so obvious here? 110 00:10:48,190 --> 00:10:49,240 There was no comma. 111 00:10:49,300 --> 00:10:50,920 I remove it and try it again. 112 00:10:53,060 --> 00:10:53,720 That's right. 113 00:10:54,170 --> 00:11:02,600 So you can see that now, guys, we got the response status to 200 and so our authentication was successful. 114 00:11:03,910 --> 00:11:10,870 So we've got the user, you can see that now and we can see our credit for the lagom so successfully 115 00:11:10,870 --> 00:11:13,630 did it and we logged into to this website. 116 00:11:14,260 --> 00:11:21,670 So that was it, guys, for this lecture and for this section, actually, we learned quite a lot of 117 00:11:21,670 --> 00:11:30,700 things in this section, such as kookiest, how to assess the website, get response from them, how 118 00:11:30,700 --> 00:11:31,400 to do that. 119 00:11:31,450 --> 00:11:36,700 In the case of Letrozole just now, which I'm sure is quite useful for you, and you are already getting 120 00:11:36,700 --> 00:11:42,950 some experience on how you can connect and execute code over the network using Python. 121 00:11:43,450 --> 00:11:48,610 So thank you very much for watching these lectures and I will see you in our next section.