Using requests to handle forms, typically, you would like to send some form encoded data into do this.
Usually you simply need to pass the directory to the data argument.
And to do that, you can usually use the request library that you are now familiar with just so it can
take action into all the encoding and formatting of your data.
So today we're going to create an example in which we're going to simulate sending e-mail data through
both request.
So this would be actually the same if you would go to the browser and send the form from the website.
But this time we're going to write the script and then run it from our terminal.
So for to do this, you can use that request dot post method.
So it's request dot post and I'll come back in here, request the dot post.
So usually you can use this in order to send the forms and specifically the put method.
And I also know the whole syntax and we're going to code this into the pie chart.
So let's create a new file.
Double-Click, new python file.
And the file, I will call it forms, so let's right actually make it a bigger import requests.
That's it.
So after you import this library and actually change this, let's create a file called Data Dictionary.
Dictionary, that's it, I hope we don't do a spelling mistake, but now what we're going to do is write
customer.
Customer puts it in the name of the customer will be Martin again, which is my name, by the way.
Then let.
Right.
Because they'll and let's put it in parenthesis, actually.
OK, customer telephone and again, through it to.
The trip to whatever and then let's write the size.
OK, so we have to size it to.
Lurch, and let's this time also other e-mail, so I will create a variable cost mail and email the
customer, it will be, let's say.
Mail at Dumaine dot com.
So any mail would work out, and pretty much that's it.
So after our data dictionaries created this, create the response variable risk phones.
Will be equal to requests.
Not post in here with our post, so lets out of the HMO that we used last time, so I write HTP and
then h t t v v dot org slash post.
And then there, though, because they underscore their dictionary.
OK, so we already created and posted the request and now let's actually print the status code of our
submitted form.
So let's write to print and in the brackets HTP status code.
That's it.
To us is TIAR.
Bracket response not.
Status.
Cold, that's it, and then if.
Response dot.
Status quo is equal to 200.
And if you remember, guys, 200 means that our action is accepted, then we'll print.
OK, response to dot text.
OK, so if what we see here is that if our state is cold or if our response is successful, then I would
like to print it.
OK, so that's it.
Let's save that.
OK, and let's go now to the terminal.
So I will exit the pipe and mold and let's now go to the folder that is our file located.
So in my case it's record, it's installed in the resources folder, so I will just go through it.
OK, and now simply to Python and then the name of the file, which is called Form CWI.
So if I run it, OK, you can see that there is an error here and let's see what there is.
So, yes, here instead of risk, I had to write response.
Response.
OK, that's it.
Let me save it, actually, and let's run it again so you can see that guys, after I run the file,
you can see the forms or the form was created here in the dictionary.
And also the next line, we posted our dear dictionary into this website.
OK, so we each of the fields in this website and now we submitted the form in the website.
You can do this with every website and you simply need to create the file, create a file like this.
And for example, if you always use certain credit, those frustration, you can just create the form
and change the link here.
So you post is submitted to every website that you visit just from the terminal and just we just file.
It is quite simple and intuitive.
So you can see that the status quo is 200 and you can see the argument that we actually are that the
customer, customer, telephone service and email address.
So this is what we completed.
And then here we get the here section, which gives additional data so you can see the content by the
host, which is the website that will assist the user agent or with what type of two will assist this
website and also the three sayadi, which is quite a large number.
And finally, you can see the J some of which is now the origin, which is the exact IP address in the
euro, which we assessed, which is htp bin dot org slash post.
So here is a case how you can create a file and submit form online over network.
Thank you very much for watching and will continue in the next video.