HTP authentication, hello, everyone.
Today, we're going to try it out, some of the authentication mechanisms that we're talking in the
previous lecture and you can see here that they have the terminal open as well.
Was the feature open in the back?
So we're actually now going to work with a pie chart.
And here I'm going to create a new file and let's select the new file.
And I will say Biasi out for basic authentication.
And let's write our code now, so I'll write to assess the part of the user bill even before Environment
Python three, and then let's import requests and then from requests dot out import HTP.
And here, since we're doing the basic authentication to import basic out and list right now, requests
that I get and here will get the euro in the parameters.
So, OK, let's work again with the GitHub dot com.
So do HTP s and who else is the GitHub user login page.
So it is api api dot get from dot com user and then lets other authentication creators write out.
Equals to A.P. basic content education.
And here I'll write you yuzu and then I will write password.
Now let's create our response from the server.
So response equals requests.
Dot, get in in the brackets.
Let's write HTP s and I'll write a pie dot get up.
Dot com slash.
User.
OK, so the same thing, and then they'll write out your user commo password that said, OK, we're
ready here, guys.
And after that, let's do the print statements or print and let's.
Right here.
Response.
Not status cold, so first of all, I'd like to see the status quo, plus let's create a string is Tara
Response Dog's status.
OK, so here obviously we're going to print what is our status code and then let's write if response
thought status code is equal to 200 or if everything is accepted, then we would like to print and dot
the log in a successful.
OK.
And plus, response dot text and also while other responses.
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,
there we go, Python and then Beyaz authentication.
So let's run this file and here we get an error.
So let me check it out.
Is not defined.
Let's see.
Yes.
So here I Friday the course.
So maybe this was the issue.
Yes.
That's from the quote once again and see if it's going to work so you can see that the response status
is 431.
And what that means guys, is that our authentication is not being accepted.
All right.
So our login is not successful here.
And this is the code that you usually see when you couldn't login in that case.
So our code works, which is good.
So this is how you do the basic authentication and this is what gets returned.
Let's now try to do the Tigist authentication.
So let's do Python to go into python mode and I'll import.
Requests.
OK.
And then from requests not out here, we'll import HTP Digest out.
OK, so this package as it exists, is so important, important.
So there's no response.
Response equals request not get.
Protected euro.
Cuomo out equals h t t p they just authentication and here we can write user password.
OK.
Let's bring in our bracket here.
We've got an error so the name requests not defined.
OK, so we need to import the requests instead of requests so requests don't get then instead of the
protected area, let's write to the GitHub login page so you can see I guess it doesn't work with the
API GitHub dot com user that we use previously.
And for that reason, we need to use another website because obviously this one doesn't support they
just authentication.
And for that reason I use this one htp binn dot org.
They just authentication, authentication user pass.
And from that website you can actually opt to the out indication.
And the only thing I need to do is to do instead of basically they just authentication.
And when they run it, you can see that the input is accepted enough to response.
You can see that we're talking to the website.
However, we're able to send request to it.
Let's now try doing this from a script so I will create a Python file here and it will be called Digest
Authentication.
OK, and let's write user hoobin EMV.
Python three in the let's import.
Requests and then I withdraw from requests, not authentication import, they just authentication this
time.
So let's write Eurail equals to h h t t p h t t p bin dot org.
And then.
That's right.
They just.
Dush out.
Then authentication user.
Plus.
But that said, there's a little bit closer.
OK, and then let's read the response response, of course, to request not get and then we want to
get the you are Al, OK, and then I'll write out EQUASS HTP.
They just authentication.
And here I write user.
And then password, that's it, and then let's forget print and so let's print response, not status
codes to us is.
And then I will do a response thought status code, which is what we're going to show here.
And then if the response, not status code, is equal to 200, then you say so we'll print.
OK, being successful, OK, and I will outhere s t r.
Response dogs chase some.
And that's it.
So if we log into the website, then we will display the response that Jason so we will actually say
that Logan is successful and will display the creditors.
So let's save that and let's see if the coach is going to be receptive.
So I will go out to the Python mold like this and illustrate airways so you can see that now we have.
That they just authentications right here, so I will to fight them, they just authentication PVA and
OK, I can get that we are getting an error here.
So let's see, what could it be so obvious here?
There was no comma.
I remove it and try it again.
That's right.
So you can see that now, guys, we got the response status to 200 and so our authentication was successful.
So we've got the user, you can see that now and we can see our credit for the lagom so successfully
did it and we logged into to this website.
So that was it, guys, for this lecture and for this section, actually, we learned quite a lot of
things in this section, such as kookiest, how to assess the website, get response from them, how
to do that.
In the case of Letrozole just now, which I'm sure is quite useful for you, and you are already getting
some experience on how you can connect and execute code over the network using Python.
So thank you very much for watching these lectures and I will see you in our next section.