1 00:00:05,110 --> 00:00:14,170 Using requests to handle forms, typically, you would like to send some form encoded data into do this. 2 00:00:14,350 --> 00:00:18,760 Usually you simply need to pass the directory to the data argument. 3 00:00:19,210 --> 00:00:27,340 And to do that, you can usually use the request library that you are now familiar with just so it can 4 00:00:27,940 --> 00:00:32,500 take action into all the encoding and formatting of your data. 5 00:00:33,340 --> 00:00:44,320 So today we're going to create an example in which we're going to simulate sending e-mail data through 6 00:00:44,420 --> 00:00:45,400 both request. 7 00:00:45,970 --> 00:00:52,230 So this would be actually the same if you would go to the browser and send the form from the website. 8 00:00:52,240 --> 00:00:57,280 But this time we're going to write the script and then run it from our terminal. 9 00:00:57,550 --> 00:01:02,920 So for to do this, you can use that request dot post method. 10 00:01:02,920 --> 00:01:14,460 So it's request dot post and I'll come back in here, request the dot post. 11 00:01:14,920 --> 00:01:21,030 So usually you can use this in order to send the forms and specifically the put method. 12 00:01:21,970 --> 00:01:29,550 And I also know the whole syntax and we're going to code this into the pie chart. 13 00:01:30,250 --> 00:01:32,020 So let's create a new file. 14 00:01:32,410 --> 00:01:35,410 Double-Click, new python file. 15 00:01:36,630 --> 00:01:46,410 And the file, I will call it forms, so let's right actually make it a bigger import requests. 16 00:01:46,590 --> 00:01:47,070 That's it. 17 00:01:48,120 --> 00:01:56,610 So after you import this library and actually change this, let's create a file called Data Dictionary. 18 00:01:58,360 --> 00:02:04,240 Dictionary, that's it, I hope we don't do a spelling mistake, but now what we're going to do is write 19 00:02:05,020 --> 00:02:05,710 customer. 20 00:02:06,880 --> 00:02:15,360 Customer puts it in the name of the customer will be Martin again, which is my name, by the way. 21 00:02:16,180 --> 00:02:17,280 Then let. 22 00:02:17,290 --> 00:02:17,800 Right. 23 00:02:18,700 --> 00:02:23,290 Because they'll and let's put it in parenthesis, actually. 24 00:02:25,190 --> 00:02:30,230 OK, customer telephone and again, through it to. 25 00:02:32,250 --> 00:02:37,690 The trip to whatever and then let's write the size. 26 00:02:38,230 --> 00:02:41,550 OK, so we have to size it to. 27 00:02:43,370 --> 00:02:55,070 Lurch, and let's this time also other e-mail, so I will create a variable cost mail and email the 28 00:02:55,070 --> 00:02:57,710 customer, it will be, let's say. 29 00:02:59,710 --> 00:03:04,370 Mail at Dumaine dot com. 30 00:03:04,720 --> 00:03:08,500 So any mail would work out, and pretty much that's it. 31 00:03:09,130 --> 00:03:16,870 So after our data dictionaries created this, create the response variable risk phones. 32 00:03:18,420 --> 00:03:22,020 Will be equal to requests. 33 00:03:23,570 --> 00:03:36,710 Not post in here with our post, so lets out of the HMO that we used last time, so I write HTP and 34 00:03:36,710 --> 00:03:45,100 then h t t v v dot org slash post. 35 00:03:45,620 --> 00:03:51,590 And then there, though, because they underscore their dictionary. 36 00:03:51,800 --> 00:04:01,340 OK, so we already created and posted the request and now let's actually print the status code of our 37 00:04:02,000 --> 00:04:02,930 submitted form. 38 00:04:03,110 --> 00:04:13,010 So let's write to print and in the brackets HTP status code. 39 00:04:13,220 --> 00:04:13,880 That's it. 40 00:04:15,860 --> 00:04:18,140 To us is TIAR. 41 00:04:20,160 --> 00:04:24,300 Bracket response not. 42 00:04:26,090 --> 00:04:27,080 Status. 43 00:04:28,360 --> 00:04:32,620 Cold, that's it, and then if. 44 00:04:34,710 --> 00:04:36,570 Response dot. 45 00:04:37,970 --> 00:04:41,530 Status quo is equal to 200. 46 00:04:41,600 --> 00:04:48,800 And if you remember, guys, 200 means that our action is accepted, then we'll print. 47 00:04:50,320 --> 00:04:54,270 OK, response to dot text. 48 00:04:54,350 --> 00:05:03,670 OK, so if what we see here is that if our state is cold or if our response is successful, then I would 49 00:05:03,670 --> 00:05:04,620 like to print it. 50 00:05:04,890 --> 00:05:07,030 OK, so that's it. 51 00:05:07,060 --> 00:05:08,410 Let's save that. 52 00:05:08,620 --> 00:05:12,190 OK, and let's go now to the terminal. 53 00:05:13,330 --> 00:05:22,590 So I will exit the pipe and mold and let's now go to the folder that is our file located. 54 00:05:22,840 --> 00:05:29,260 So in my case it's record, it's installed in the resources folder, so I will just go through it. 55 00:05:29,470 --> 00:05:37,360 OK, and now simply to Python and then the name of the file, which is called Form CWI. 56 00:05:39,620 --> 00:05:45,480 So if I run it, OK, you can see that there is an error here and let's see what there is. 57 00:05:46,880 --> 00:05:52,160 So, yes, here instead of risk, I had to write response. 58 00:05:54,030 --> 00:05:54,760 Response. 59 00:05:54,780 --> 00:05:55,600 OK, that's it. 60 00:05:56,580 --> 00:06:04,470 Let me save it, actually, and let's run it again so you can see that guys, after I run the file, 61 00:06:05,580 --> 00:06:09,240 you can see the forms or the form was created here in the dictionary. 62 00:06:09,570 --> 00:06:15,360 And also the next line, we posted our dear dictionary into this website. 63 00:06:15,600 --> 00:06:22,560 OK, so we each of the fields in this website and now we submitted the form in the website. 64 00:06:22,570 --> 00:06:28,830 You can do this with every website and you simply need to create the file, create a file like this. 65 00:06:29,040 --> 00:06:35,730 And for example, if you always use certain credit, those frustration, you can just create the form 66 00:06:35,730 --> 00:06:37,770 and change the link here. 67 00:06:38,190 --> 00:06:44,340 So you post is submitted to every website that you visit just from the terminal and just we just file. 68 00:06:44,370 --> 00:06:46,830 It is quite simple and intuitive. 69 00:06:47,850 --> 00:06:55,560 So you can see that the status quo is 200 and you can see the argument that we actually are that the 70 00:06:55,560 --> 00:07:00,690 customer, customer, telephone service and email address. 71 00:07:00,960 --> 00:07:02,300 So this is what we completed. 72 00:07:02,550 --> 00:07:09,900 And then here we get the here section, which gives additional data so you can see the content by the 73 00:07:09,900 --> 00:07:17,430 host, which is the website that will assist the user agent or with what type of two will assist this 74 00:07:17,430 --> 00:07:22,020 website and also the three sayadi, which is quite a large number. 75 00:07:22,620 --> 00:07:30,210 And finally, you can see the J some of which is now the origin, which is the exact IP address in the 76 00:07:30,210 --> 00:07:35,610 euro, which we assessed, which is htp bin dot org slash post. 77 00:07:36,060 --> 00:07:41,910 So here is a case how you can create a file and submit form online over network. 78 00:07:42,170 --> 00:07:45,480 Thank you very much for watching and will continue in the next video.