{"id":2690,"date":"2020-04-18T11:22:12","date_gmt":"2020-04-18T11:22:12","guid":{"rendered":"https:\/\/www.staging6.machinelearningplus.com\/?p=2690"},"modified":"2022-10-10T11:16:43","modified_gmt":"2022-10-10T11:16:43","slug":"requests-in-python","status":"publish","type":"post","link":"https:\/\/machinelearningplus.com\/python\/requests-in-python\/","title":{"rendered":"Requests in Python Tutorial &#8211; How to send HTTP requests in Python?"},"content":{"rendered":"<p><em>Requests is an elegant and simple Python library built to handle HTTP requests in python easily. It allows you make GET, POST, PUT and other types of requests and process the received response in a flexible Pythonic way.<\/em><\/p>\r\n<h2 id=\"contents\">Contents<\/h2>\r\n<ol>\r\n<li>Introduction to Requests Library<\/li>\r\n<li>What is a GET and POST request?<\/li>\r\n<li>GET Method<\/li>\r\n<li>Status Code<\/li>\r\n<li>Contents of the Response Object<\/li>\r\n<li>The Content<\/li>\r\n<li>Full HTML source as Text<\/li>\r\n<li>Retrieving an image from website<\/li>\r\n<li>Headers<\/li>\r\n<li>How to set Query String Parameters<\/li>\r\n<li>POST Method<\/li>\r\n<li>PUT Method<\/li>\r\n<li>DELETE Method<\/li>\r\n<li>PATCH Method<\/li>\r\n<li>HEAD Method<\/li>\r\n<li>Request Header<\/li>\r\n<li>Inspecting the request made<\/li>\r\n<li>Authentication<\/li>\r\n<li>Time out<\/li>\r\n<li>SSL Certification<\/li>\r\n<\/ol>\r\n<h2 id=\"introduction-to-requests-library\">Introduction to Requests Library<\/h2>\r\n<p><strong>Requests is an elegant and simple Python library built to handle HTTP requests in python easily.<\/strong> But what is a HTTP request? <strong>HTTP is a set of protocols designed to enable communication between clients and servers.<\/strong><\/p>\r\n<p>A client is typically a local computer or device similar to what you are using to view this page. A HTTP request is the message sent (or received) from your local computer to a web server hosting, typically hosting a website.<\/p>\r\n<p>For example, when you go to any internet website from your browser, the browser is sending a HTTP request and receives an appropriate &#8216;response&#8217; from the host server.<\/p>\r\n<p>Requests is an easy-to-use library with a lot of features ranging from passing additional parameters in URLs, sending custom headers, SSL Verification, processing the received response etc.<\/p>\r\n<!-- \/wp:post-content -->\r\n\r\n<!-- wp:paragraph -->\r\n<h2 id=\"what-is-a-get-and-post-request-\">What is a GET and POST request?<\/h2>\r\n<p>A <strong>GET request is used to request data from a specific server<\/strong>. It is the most common type of request.<\/p>\r\n<p>This is synonymous to you visiting the homepage of a website from your browser. <strong>Another common type of request is the POST request, which is used to send data to a host server for further processing, like, to update a resource, such as a database.<\/strong><\/p>\r\n<p>What is this synonymous to in real world?<\/p>\r\n<p>For example, most data that you submit through forms in various websites is sent and processed as a POST request. Besides this, using requests you can add additional content like header information, form data, multipart files, and parameters via simple Python libraries. You don&#8217;t need to manually append the query strings to your URLs.<\/p>\r\n<p>What does that practically mean?<\/p>\r\n<p>For example, if you search for something, say the string &#8216;babies&#8217; in google, your browser sends a GET request to Google server by appending the query string to the url.<\/p>\r\n<p>So if you check the url in your address bar, you should see something like: <code>https:\/\/www.google.com\/search?q=babies<\/code> Sometimes, there are more information making the query strings complex to construct.<\/p>\r\n<p>With <code>requests<\/code> library, you don&#8217;t have to explicity construct such query strings. But rather pass it as additional parameter to <code>requests.get()<\/code>.<\/p>\r\n<p>What makes requests really stand out is, the received response is packages as a standardized <code>Response<\/code> object. It will contain all the response data (status, content, cookies etc). This makes further inspection and manipulation reliable and convenient.<\/p>\r\n<p>Let&#8217;s start by downloading the requests library using: <code>pip install requests<\/code>.<\/p>\r\n<pre><code class=\"lang-python\">!pip <span class=\"hljs-keyword\">install<\/span> requests\r\n<\/code><\/pre>\r\n<p>Then import the library to use it in your program use the <code>import requests<\/code> command.<\/p>\r\n<pre><code class=\"lang-python\"><span class=\"hljs-keyword\">import<\/span> requests\r\n<span class=\"hljs-keyword\">from<\/span> pprint <span class=\"hljs-keyword\">import<\/span> pprint  <span class=\"hljs-comment\"># prettyprint<\/span>\r\n<\/code><\/pre>\r\n<p>Now let&#8217;s look into the details of request library and some of the important features.<\/p>\r\n<h2 id=\"get-method\">GET Method<\/h2>\r\n<p>Lets try to get some information from the official python website &#8211; <a href=\"https:\/\/www.python.org\/\">https:\/\/www.python.org\/<\/a>. You can use any public site. All you need to do is call <code>requests.get(url_name)<\/code>.<\/p>\r\n<p>When you ping a website or portal for information it&#8217;s considered as &#8216;making a request&#8217;. <code>requests.get()<\/code> is used exactly for this purpose. You need to specify the web address that you need to ping as an argument to the function.<\/p>\r\n<pre><code class=\"lang-python\"><span class=\"hljs-attr\">r<\/span> = requests.get(<span class=\"hljs-string\">'https:\/\/www.python.org\/'<\/span>)\r\n<\/code><\/pre>\r\n<p>The information that we got from the website will be stored in the <code>Response<\/code> object we created <code>r<\/code>. You can extract many features from this response object, like if you need to get the cookies that server sent, all you need to do is print <code>r.cookies<\/code>.<\/p>\r\n<p>Now as I have requested the data from the website, to check whether it has worked properly, let&#8217;s try priniting the <code>r<\/code> value.<\/p>\r\n<pre><code class=\"lang-python\"><span class=\"hljs-function\"><span class=\"hljs-title\">print<\/span><span class=\"hljs-params\">(r)<\/span><\/span>\r\n<\/code><\/pre>\r\n<pre><code>&lt;Response <span class=\"hljs-string\">[200]<\/span>&gt;\r\n<\/code><\/pre>\r\n<p>You can see that we have got <code>Resonse [200]<\/code>. Let&#8217;s look into what this means.<\/p>\r\n<h2 id=\"status-code\">STATUS Code<\/h2>\r\n<p><strong>Status codes are issued by a server in response to a client&#8217;s request made to the server.<\/strong> Use the <code>r.status_code<\/code> command to return the status code for your request.<\/p>\r\n<pre><code class=\"lang-python\"><span class=\"hljs-function\"><span class=\"hljs-title\">print<\/span><span class=\"hljs-params\">(r.status_code)<\/span><\/span>\r\n<\/code><\/pre>\r\n<pre><code><span class=\"hljs-number\">200<\/span>\r\n<\/code><\/pre>\r\n<p>We have got a response of 200 which means the request is success. A response of <strong>200<\/strong> means <strong>Success<\/strong>. A response of <strong>300<\/strong> means <strong>Redirected<\/strong>. A response of <strong>400<\/strong> means <strong>Client Error<\/strong>.<\/p>\r\n<p>A response of <strong>500<\/strong> means <strong>Server Error<\/strong>. A response of <strong>404<\/strong> means <strong>Page Not Found Error<\/strong>. In general, any status code less than 400 means, the request was processed successfully.<\/p>\r\n<p>If it is 400 and above, some sort of error occurred. You may need to use the if else statement about whether to further proceed into the code depending upon the status code you recieved from the server, as you don&#8217;t need to further run your program after you have got an error. Use the following code below in that case:<\/p>\r\n<pre><code class=\"lang-python\"><span class=\"hljs-keyword\">if<\/span> r<span class=\"hljs-selector-class\">.status_code<\/span> == <span class=\"hljs-number\">200<\/span>:\r\n    print(<span class=\"hljs-string\">'Success'<\/span>)\r\nelif r<span class=\"hljs-selector-class\">.status_code<\/span> == <span class=\"hljs-number\">404<\/span>:\r\n    print(<span class=\"hljs-string\">\"Page not found\"<\/span>)\r\n<\/code><\/pre>\r\n<pre><code><span class=\"hljs-attribute\">Success<\/span>\r\n<\/code><\/pre>\r\n<h4>\u00a0<\/h4>\r\n<p>&nbsp;<\/p>\r\n<h2 id=\"contents-of-the-response-object\">Contents of the Response object<\/h2>\r\n<p><strong><code>dir(r)<\/code> function is used to get details about what all useful information we can get from the data we retrived.<\/strong><\/p>\r\n<pre><code class=\"lang-python\">r_attribs = [<span class=\"hljs-built_in\">c<\/span> <span class=\"hljs-keyword\">for<\/span> <span class=\"hljs-built_in\">c<\/span> <span class=\"hljs-keyword\">in<\/span> dir(r) <span class=\"hljs-keyword\">if<\/span> not <span class=\"hljs-built_in\">c<\/span>.startswith(<span class=\"hljs-string\">\"_\"<\/span>)]\r\nr_attribs\r\n<\/code><\/pre>\r\n<pre><code>[<span class=\"hljs-symbol\">'apparent_encoding<\/span>',\r\n <span class=\"hljs-symbol\">'close<\/span>',\r\n <span class=\"hljs-symbol\">'connection<\/span>',\r\n <span class=\"hljs-symbol\">'content<\/span>',\r\n <span class=\"hljs-symbol\">'cookies<\/span>',\r\n <span class=\"hljs-symbol\">'elapsed<\/span>',\r\n <span class=\"hljs-symbol\">'encoding<\/span>',\r\n <span class=\"hljs-symbol\">'headers<\/span>',\r\n <span class=\"hljs-symbol\">'history<\/span>',\r\n <span class=\"hljs-symbol\">'is_permanent_redirect<\/span>',\r\n <span class=\"hljs-symbol\">'is_redirect<\/span>',\r\n <span class=\"hljs-symbol\">'iter_content<\/span>',\r\n <span class=\"hljs-symbol\">'iter_lines<\/span>',\r\n <span class=\"hljs-symbol\">'json<\/span>',\r\n <span class=\"hljs-symbol\">'links<\/span>',\r\n <span class=\"hljs-symbol\">'next<\/span>',\r\n <span class=\"hljs-symbol\">'ok<\/span>',\r\n <span class=\"hljs-symbol\">'raise_for_status<\/span>',\r\n <span class=\"hljs-symbol\">'raw<\/span>',\r\n <span class=\"hljs-symbol\">'reason<\/span>',\r\n <span class=\"hljs-symbol\">'request<\/span>',\r\n <span class=\"hljs-symbol\">'status_code<\/span>',\r\n <span class=\"hljs-symbol\">'text<\/span>',\r\n <span class=\"hljs-symbol\">'url<\/span>']\r\n<\/code><\/pre>\r\n<p>You can see that there are several commands available such as <code>headers<\/code>, <code>status_code<\/code>, <code>content<\/code>, <code>cookies<\/code> etc. You can also use <code>help(r)<\/code> command to get more info about each of these. I&#8217;m showing some of the help info that&#8217;s useful below.<\/p>\r\n<pre><code class=\"lang-python\">print(<span class=\"hljs-name\">help<\/span>(<span class=\"hljs-name\">r<\/span>))\r\n<\/code><\/pre>\r\n<pre><code>Help <span class=\"hljs-keyword\">on<\/span> Response <span class=\"hljs-keyword\">in<\/span> <span class=\"hljs-keyword\">module<\/span> requests.models <span class=\"hljs-built_in\">object<\/span>:\r\n\r\n<span class=\"hljs-keyword\">class<\/span> Response(builtins.<span class=\"hljs-built_in\">object<\/span>)\r\n |  The :<span class=\"hljs-keyword\">class<\/span>:`Response &lt;Response&gt;` <span class=\"hljs-built_in\">object<\/span>, which contains a\r\n |  server<span class=\"hljs-comment\">'s response to an HTTP request.<\/span>\r\n |  \r\n |  Methods defined here:\r\n |  \r\n |  __bool__(self)\r\n |      Returns <span class=\"hljs-literal\">True<\/span> <span class=\"hljs-keyword\">if<\/span> :attr:`status_code` <span class=\"hljs-keyword\">is<\/span> less than <span class=\"hljs-number\">400.<\/span>\r\n |      \r\n |      This attribute checks <span class=\"hljs-keyword\">if<\/span> the status code <span class=\"hljs-keyword\">of<\/span> the response <span class=\"hljs-keyword\">is<\/span> between\r\n |      <span class=\"hljs-number\">400<\/span> <span class=\"hljs-keyword\">and<\/span> <span class=\"hljs-number\">600<\/span> <span class=\"hljs-keyword\">to<\/span> see <span class=\"hljs-keyword\">if<\/span> there was a client <span class=\"hljs-keyword\">error<\/span> <span class=\"hljs-keyword\">or<\/span> a server <span class=\"hljs-keyword\">error<\/span>. <span class=\"hljs-keyword\">If<\/span>\r\n |      the status code, <span class=\"hljs-keyword\">is<\/span> between <span class=\"hljs-number\">200<\/span> <span class=\"hljs-keyword\">and<\/span> <span class=\"hljs-number\">400<\/span>, this will <span class=\"hljs-keyword\">return<\/span> <span class=\"hljs-literal\">True<\/span>. This\r\n |      <span class=\"hljs-keyword\">is<\/span> **<span class=\"hljs-keyword\">not<\/span>** a check <span class=\"hljs-keyword\">to<\/span> see <span class=\"hljs-keyword\">if<\/span> the response code <span class=\"hljs-keyword\">is<\/span> ``<span class=\"hljs-number\">200<\/span> OK``.\r\n |  \r\n |  __enter__(self)\r\n |  \r\n |  __exit__(self, *args)\r\n |  \r\n |  __getstate__(self)\r\n |  \r\n |  __init__(self)\r\n |      Initialize self.  See help(type(self)) <span class=\"hljs-keyword\">for<\/span> accurate signature.\r\n |  \r\n |  __iter__(self)\r\n |      Allows you <span class=\"hljs-keyword\">to<\/span> use a response <span class=\"hljs-keyword\">as<\/span> an iterator.\r\n |  \r\n |  __nonzero__(self)\r\n |      Returns <span class=\"hljs-literal\">True<\/span> <span class=\"hljs-keyword\">if<\/span> :attr:`status_code` <span class=\"hljs-keyword\">is<\/span> less than <span class=\"hljs-number\">400.<\/span>\r\n |      \r\n |      This attribute checks <span class=\"hljs-keyword\">if<\/span> the status code <span class=\"hljs-keyword\">of<\/span> the response <span class=\"hljs-keyword\">is<\/span> between\r\n |      <span class=\"hljs-number\">400<\/span> <span class=\"hljs-keyword\">and<\/span> <span class=\"hljs-number\">600<\/span> <span class=\"hljs-keyword\">to<\/span> see <span class=\"hljs-keyword\">if<\/span> there was a client <span class=\"hljs-keyword\">error<\/span> <span class=\"hljs-keyword\">or<\/span> a server <span class=\"hljs-keyword\">error<\/span>. <span class=\"hljs-keyword\">If<\/span>\r\n |      the status code, <span class=\"hljs-keyword\">is<\/span> between <span class=\"hljs-number\">200<\/span> <span class=\"hljs-keyword\">and<\/span> <span class=\"hljs-number\">400<\/span>, this will <span class=\"hljs-keyword\">return<\/span> <span class=\"hljs-literal\">True<\/span>. This\r\n |      <span class=\"hljs-keyword\">is<\/span> **<span class=\"hljs-keyword\">not<\/span>** a check <span class=\"hljs-keyword\">to<\/span> see <span class=\"hljs-keyword\">if<\/span> the response code <span class=\"hljs-keyword\">is<\/span> ``<span class=\"hljs-number\">200<\/span> OK``.\r\n |  \r\n |  __repr__(self)\r\n |      <span class=\"hljs-keyword\">Return<\/span> repr(self).\r\n |  \r\n |  __setstate__(self, state)\r\n |  \r\n |  close(self)\r\n |      Releases the connection back <span class=\"hljs-keyword\">to<\/span> the pool. Once this method has been\r\n |      called the underlying ``raw`` <span class=\"hljs-built_in\">object<\/span> must <span class=\"hljs-keyword\">not<\/span> be accessed again.\r\n |      \r\n |      *Note: Should <span class=\"hljs-keyword\">not<\/span> normally need <span class=\"hljs-keyword\">to<\/span> be called explicitly.*\r\n |  \r\n |  iter_content(self, chunk_size=<span class=\"hljs-number\">1<\/span>, decode_unicode=<span class=\"hljs-literal\">False<\/span>)\r\n |      Iterates over the response data.  <span class=\"hljs-keyword\">When<\/span> stream=<span class=\"hljs-literal\">True<\/span> <span class=\"hljs-keyword\">is<\/span> <span class=\"hljs-keyword\">set<\/span> <span class=\"hljs-keyword\">on<\/span> the\r\n |      request, this avoids reading the content at once <span class=\"hljs-keyword\">into<\/span> memory <span class=\"hljs-keyword\">for<\/span>\r\n |      large responses.  The chunk size <span class=\"hljs-keyword\">is<\/span> the number <span class=\"hljs-keyword\">of<\/span> bytes it should\r\n |      read <span class=\"hljs-keyword\">into<\/span> memory.  This <span class=\"hljs-keyword\">is<\/span> <span class=\"hljs-keyword\">not<\/span> necessarily the length <span class=\"hljs-keyword\">of<\/span> <span class=\"hljs-keyword\">each<\/span> item\r\n |      returned <span class=\"hljs-keyword\">as<\/span> decoding can <span class=\"hljs-keyword\">take<\/span> place.\r\n |      \r\n |      chunk_size must be <span class=\"hljs-keyword\">of<\/span> type int <span class=\"hljs-keyword\">or<\/span> None. A value <span class=\"hljs-keyword\">of<\/span> None will\r\n |      <span class=\"hljs-keyword\">function<\/span> differently depending <span class=\"hljs-keyword\">on<\/span> the value <span class=\"hljs-keyword\">of<\/span> `stream`.\r\n |      stream=<span class=\"hljs-literal\">True<\/span> will read data <span class=\"hljs-keyword\">as<\/span> it arrives <span class=\"hljs-keyword\">in<\/span> whatever size the\r\n |      chunks are received. <span class=\"hljs-keyword\">If<\/span> stream=<span class=\"hljs-literal\">False<\/span>, data <span class=\"hljs-keyword\">is<\/span> returned <span class=\"hljs-keyword\">as<\/span>\r\n |      a <span class=\"hljs-built_in\">single<\/span> chunk.\r\n |      \r\n |      <span class=\"hljs-keyword\">If<\/span> decode_unicode <span class=\"hljs-keyword\">is<\/span> <span class=\"hljs-literal\">True<\/span>, content will be decoded <span class=\"hljs-keyword\">using<\/span> the best\r\n |      available encoding based <span class=\"hljs-keyword\">on<\/span> the response.\r\n |  \r\n |  iter_lines(self, chunk_size=<span class=\"hljs-number\">512<\/span>, decode_unicode=<span class=\"hljs-literal\">False<\/span>, delimiter=None)\r\n |      Iterates over the response data, one line at a time.  <span class=\"hljs-keyword\">When<\/span>\r\n |      stream=<span class=\"hljs-literal\">True<\/span> <span class=\"hljs-keyword\">is<\/span> <span class=\"hljs-keyword\">set<\/span> <span class=\"hljs-keyword\">on<\/span> the request, this avoids reading the\r\n |      content at once <span class=\"hljs-keyword\">into<\/span> memory <span class=\"hljs-keyword\">for<\/span> large responses.\r\n |      \r\n |      .. note:: This method <span class=\"hljs-keyword\">is<\/span> <span class=\"hljs-keyword\">not<\/span> reentrant safe.\r\n |  \r\n |  json(self, **kwargs)\r\n |      Returns the json-encoded content <span class=\"hljs-keyword\">of<\/span> a response, <span class=\"hljs-keyword\">if<\/span> any.\r\n |      \r\n |      :param \\*\\*kwargs: <span class=\"hljs-keyword\">Optional<\/span> arguments that ``json.loads`` takes.\r\n |      :raises ValueError: <span class=\"hljs-keyword\">If<\/span> the response body does <span class=\"hljs-keyword\">not<\/span> contain valid json.\r\n |  \r\n |  raise_for_status(self)\r\n |      Raises stored :<span class=\"hljs-keyword\">class<\/span>:`HTTPError`, <span class=\"hljs-keyword\">if<\/span> one occurred.\r\n |  \r\n |  ----------------------------------------------------------------------\r\n |  Data descriptors defined here:\r\n |  \r\n |  __dict__\r\n |      dictionary <span class=\"hljs-keyword\">for<\/span> instance variables (<span class=\"hljs-keyword\">if<\/span> defined)\r\n |  \r\n |  __weakref__\r\n |      list <span class=\"hljs-keyword\">of<\/span> weak references <span class=\"hljs-keyword\">to<\/span> the <span class=\"hljs-built_in\">object<\/span> (<span class=\"hljs-keyword\">if<\/span> defined)\r\n |  \r\n |  apparent_encoding\r\n |      The apparent encoding, provided <span class=\"hljs-keyword\">by<\/span> the chardet library.\r\n |  \r\n |  content\r\n |      Content <span class=\"hljs-keyword\">of<\/span> the response, <span class=\"hljs-keyword\">in<\/span> bytes.\r\n |  \r\n |  is_permanent_redirect\r\n |      <span class=\"hljs-literal\">True<\/span> <span class=\"hljs-keyword\">if<\/span> this Response one <span class=\"hljs-keyword\">of<\/span> the permanent versions <span class=\"hljs-keyword\">of<\/span> redirect.\r\n |  \r\n |  is_redirect\r\n |      <span class=\"hljs-literal\">True<\/span> <span class=\"hljs-keyword\">if<\/span> this Response <span class=\"hljs-keyword\">is<\/span> a well-formed HTTP redirect that could have\r\n |      been processed automatically (<span class=\"hljs-keyword\">by<\/span> :meth:`Session.resolve_redirects`).\r\n |  \r\n |  links\r\n |      Returns the parsed header links <span class=\"hljs-keyword\">of<\/span> the response, <span class=\"hljs-keyword\">if<\/span> any.\r\n |  \r\n |  <span class=\"hljs-keyword\">next<\/span>\r\n |      Returns a PreparedRequest <span class=\"hljs-keyword\">for<\/span> the <span class=\"hljs-keyword\">next<\/span> request <span class=\"hljs-keyword\">in<\/span> a redirect chain, <span class=\"hljs-keyword\">if<\/span> there <span class=\"hljs-keyword\">is<\/span> one.\r\n |  \r\n |  ok\r\n |      Returns <span class=\"hljs-literal\">True<\/span> <span class=\"hljs-keyword\">if<\/span> :attr:`status_code` <span class=\"hljs-keyword\">is<\/span> less than <span class=\"hljs-number\">400<\/span>, <span class=\"hljs-literal\">False<\/span> <span class=\"hljs-keyword\">if<\/span> <span class=\"hljs-keyword\">not<\/span>.\r\n |      \r\n |      This attribute checks <span class=\"hljs-keyword\">if<\/span> the status code <span class=\"hljs-keyword\">of<\/span> the response <span class=\"hljs-keyword\">is<\/span> between\r\n |      <span class=\"hljs-number\">400<\/span> <span class=\"hljs-keyword\">and<\/span> <span class=\"hljs-number\">600<\/span> <span class=\"hljs-keyword\">to<\/span> see <span class=\"hljs-keyword\">if<\/span> there was a client <span class=\"hljs-keyword\">error<\/span> <span class=\"hljs-keyword\">or<\/span> a server <span class=\"hljs-keyword\">error<\/span>. <span class=\"hljs-keyword\">If<\/span>\r\n |      the status code <span class=\"hljs-keyword\">is<\/span> between <span class=\"hljs-number\">200<\/span> <span class=\"hljs-keyword\">and<\/span> <span class=\"hljs-number\">400<\/span>, this will <span class=\"hljs-keyword\">return<\/span> <span class=\"hljs-literal\">True<\/span>. This\r\n |      <span class=\"hljs-keyword\">is<\/span> **<span class=\"hljs-keyword\">not<\/span>** a check <span class=\"hljs-keyword\">to<\/span> see <span class=\"hljs-keyword\">if<\/span> the response code <span class=\"hljs-keyword\">is<\/span> ``<span class=\"hljs-number\">200<\/span> OK``.\r\n |  \r\n |  <span class=\"hljs-keyword\">text<\/span>\r\n |      Content <span class=\"hljs-keyword\">of<\/span> the response, <span class=\"hljs-keyword\">in<\/span> <span class=\"hljs-keyword\">unicode<\/span>.\r\n |      \r\n |      <span class=\"hljs-keyword\">If<\/span> Response.encoding <span class=\"hljs-keyword\">is<\/span> None, encoding will be guessed <span class=\"hljs-keyword\">using<\/span>\r\n |      ``chardet``.\r\n |      \r\n |      The encoding <span class=\"hljs-keyword\">of<\/span> the response content <span class=\"hljs-keyword\">is<\/span> determined based solely <span class=\"hljs-keyword\">on<\/span> HTTP\r\n |      headers, following RFC <span class=\"hljs-number\">2616<\/span> <span class=\"hljs-keyword\">to<\/span> the letter. <span class=\"hljs-keyword\">If<\/span> you can <span class=\"hljs-keyword\">take<\/span> advantage <span class=\"hljs-keyword\">of<\/span>\r\n |      non-HTTP knowledge <span class=\"hljs-keyword\">to<\/span> make a better guess at the encoding, you should\r\n |      <span class=\"hljs-keyword\">set<\/span> ``r.encoding`` appropriately before accessing this <span class=\"hljs-keyword\">property<\/span>.\r\n |  \r\n |  ----------------------------------------------------------------------\r\n |  Data <span class=\"hljs-keyword\">and<\/span> other attributes defined here:\r\n |  \r\n |  __attrs__ = [<span class=\"hljs-comment\">'_content', 'status_code', 'headers', 'url', 'history', '...<\/span>\r\n\r\nNone\r\n<\/code><\/pre>\r\n<h2 id=\"the-content\">The Content<\/h2>\r\n<p>The output from the <code>requests.get()<\/code>, that is, the <code>Response<\/code> object contains many useful information. <strong>Use the <code>r.content<\/code> command to get the access to the raw data we recieved as output.<\/strong><\/p>\r\n<p>This is the raw output of the html content behind the URL we requested, which in this case is <a href=\"https:\/\/www.python.org\/\">https:\/\/www.python.org\/<\/a>.<\/p>\r\n<pre><code class=\"lang-python\"># Printing <span class=\"hljs-built_in\">first<\/span> <span class=\"hljs-number\">200<\/span> characters\r\n<span class=\"hljs-built_in\">print<\/span>(r.<span class=\"hljs-built_in\">content<\/span>[:<span class=\"hljs-number\">200<\/span>])\r\n<\/code><\/pre>\r\n<pre><code>b'<span class=\"hljs-meta\">&lt;!doctype html&gt;<\/span>\\n<span class=\"hljs-comment\">&lt;!--[if lt IE 7]&gt;   &lt;html class=\"no-js ie6 lt-ie7 lt-ie8 lt-ie9\"&gt;   &lt;![endif]--&gt;<\/span>\\n<span class=\"hljs-comment\">&lt;!--[if IE 7]&gt;      &lt;html class=\"no-js ie7 lt-ie8 lt-ie9\"&gt;          &lt;![endif]--&gt;<\/span>\\n<span class=\"hljs-comment\">&lt;!--[if IE 8]&gt;      &lt;h'<\/span>\r\n<\/code><\/pre>\r\n<p>While <code>.content<\/code> gives you access to the raw bytes of the response, you need to convert them into a string using a character encoding such as UTF-8.<\/p>\r\n<p>You get that directly by using another stored attribute in the response called the <code>r.text<\/code>.<\/p>\r\n<h2 id=\"the-full-html-source-as-text\">The Full HTML source as Text<\/h2>\r\n<p><strong>Use the <code>text()<\/code> command to get the content from the website as a unicode response.<\/strong> Unicode is a standard way for encoding characters. Unicode string is a python data structure that can store zero or more unicode characters. This output should match with what you see when you right click on the webpage and view its page source.<\/p>\r\n<pre><code class=\"lang-python\"><span class=\"hljs-function\"><span class=\"hljs-title\">print<\/span><span class=\"hljs-params\">(r.text[:<span class=\"hljs-number\">800<\/span>])<\/span><\/span>\r\n<\/code><\/pre>\r\n<pre><code><span class=\"hljs-meta\">&lt;!doctype html&gt;<\/span>\r\n<span class=\"hljs-comment\">&lt;!--[if lt IE 7]&gt;   &lt;html class=\"no-js ie6 lt-ie7 lt-ie8 lt-ie9\"&gt;   &lt;![endif]--&gt;<\/span>\r\n<span class=\"hljs-comment\">&lt;!--[if IE 7]&gt;      &lt;html class=\"no-js ie7 lt-ie8 lt-ie9\"&gt;          &lt;![endif]--&gt;<\/span>\r\n<span class=\"hljs-comment\">&lt;!--[if IE 8]&gt;      &lt;html class=\"no-js ie8 lt-ie9\"&gt;                 &lt;![endif]--&gt;<\/span>\r\n<span class=\"hljs-comment\">&lt;!--[if gt IE 8]&gt;&lt;!--&gt;<\/span><span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">html<\/span> <span class=\"hljs-attr\">class<\/span>=<span class=\"hljs-string\">\"no-js\"<\/span> <span class=\"hljs-attr\">lang<\/span>=<span class=\"hljs-string\">\"en\"<\/span> <span class=\"hljs-attr\">dir<\/span>=<span class=\"hljs-string\">\"ltr\"<\/span>&gt;<\/span>  <span class=\"hljs-comment\">&lt;!--&lt;![endif]--&gt;<\/span>\r\n\r\n<span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">head<\/span>&gt;<\/span>\r\n    <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">meta<\/span> <span class=\"hljs-attr\">charset<\/span>=<span class=\"hljs-string\">\"utf-8\"<\/span>&gt;<\/span>\r\n    <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">meta<\/span> <span class=\"hljs-attr\">http-equiv<\/span>=<span class=\"hljs-string\">\"X-UA-Compatible\"<\/span> <span class=\"hljs-attr\">content<\/span>=<span class=\"hljs-string\">\"IE=edge\"<\/span>&gt;<\/span>\r\n\r\n    <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">link<\/span> <span class=\"hljs-attr\">rel<\/span>=<span class=\"hljs-string\">\"prefetch\"<\/span> <span class=\"hljs-attr\">href<\/span>=<span class=\"hljs-string\">\"\/\/ajax.googleapis.com\/ajax\/libs\/jquery\/1.8.2\/jquery.min.js\"<\/span>&gt;<\/span>\r\n\r\n    <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">meta<\/span> <span class=\"hljs-attr\">name<\/span>=<span class=\"hljs-string\">\"application-name\"<\/span> <span class=\"hljs-attr\">content<\/span>=<span class=\"hljs-string\">\"Python.org\"<\/span>&gt;<\/span>\r\n    <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">meta<\/span> <span class=\"hljs-attr\">name<\/span>=<span class=\"hljs-string\">\"msapplication-tooltip\"<\/span> <span class=\"hljs-attr\">content<\/span>=<span class=\"hljs-string\">\"The official home of the Python Programming Language\"<\/span>&gt;<\/span>\r\n    <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">meta<\/span> <span class=\"hljs-attr\">name<\/span>=<span class=\"hljs-string\">\"apple-mobile-web-app-title\"<\/span> <span class=\"hljs-attr\">content<\/span>=<span class=\"hljs-string\">\"Python.org\"<\/span>&gt;<\/span>\r\n    <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">meta<\/span> <span class=\"hljs-attr\">name<\/span>=<span class=\"hljs-string\">\"apple-mobile-web-app-capable\"<\/span> <span class=\"hljs-attr\">co<\/span><\/span>\r\n<\/code><\/pre>\r\n<h2 id=\"retrieving-an-image-from-the-website\">Retrieving an image from the website<\/h2>\r\n<p>Use the same <code>requests.get()<\/code> command to retrieve the image. I am using the image from the url &#8211; <code>https:\/\/www.python.org\/static\/img\/python-logo.png<\/code> The received response is also a <code>Response<\/code> object. The image is stored in <code>r.content<\/code>, which you can write to a file.<\/p>\r\n<p>This means, whatever be the content of the received response, be it text or image, it is stored in the <code>content<\/code> attribute.<\/p>\r\n<pre><code class=\"lang-python\"># <span class=\"hljs-type\">Retrieve<\/span> image <span class=\"hljs-keyword\">and<\/span> save <span class=\"hljs-keyword\">in<\/span> <span class=\"hljs-keyword\">local<\/span>\r\nr = requests.get(<span class=\"hljs-string\">\"https:\/\/www.python.org\/static\/img\/python-logo.png\"<\/span>)\r\n\r\n# <span class=\"hljs-symbol\">'wb'<\/span> represents write byte mode\r\n<span class=\"hljs-keyword\">with<\/span> <span class=\"hljs-keyword\">open<\/span>(<span class=\"hljs-symbol\">'file<\/span>.png',<span class=\"hljs-symbol\">'wb'<\/span>) <span class=\"hljs-keyword\">as<\/span> f:\r\n    f.write(r.content)\r\n<\/code><\/pre>\r\n<p>The image from the website will be downloaded to the folder in which you are running the program.<\/p>\r\n<h2 id=\"headers\">Headers<\/h2>\r\n<p>Most webpages you visite will contain header, which contains various metadata. <strong>Use the <code>r.headers<\/code> command to access the information in the header of the page.<\/strong> What does <code>r.header<\/code> contain? If you look at the output from the <code>r.header<\/code>, you\u00e2\u20ac\u2122ll see that it is actually a serialized JSON content.<\/p>\r\n<p>More information like metadata about the response, it is stored in the header. It gives you many information such as the content type of the response payload, a time limit on how long to cache the response, and more. This will return you a dictionary-like object, allowing you to access header values by key.<\/p>\r\n<pre><code class=\"lang-python\"><span class=\"hljs-comment\"># Header contents<\/span>\r\n<span class=\"hljs-keyword\">for<\/span> key, <span class=\"hljs-built_in\">value<\/span> <span class=\"hljs-keyword\">in<\/span> r.headers.<span class=\"hljs-keyword\">items<\/span>():\r\n  print(key, <span class=\"hljs-string\">\":\"<\/span>, <span class=\"hljs-built_in\">value<\/span>)\r\n<\/code><\/pre>\r\n<pre><code>Server : <span class=\"hljs-type\">nginx<\/span>\r\nContent-<span class=\"hljs-keyword\">Type<\/span> <span class=\"hljs-type\">: <\/span>text\/html; charset=utf-<span class=\"hljs-number\">8<\/span>\r\nX-Frame-Options : <span class=\"hljs-type\">DENY<\/span>\r\nVia : 1.1 <span class=\"hljs-type\">vegur<\/span>, <span class=\"hljs-number\">1.1<\/span> varnish, <span class=\"hljs-number\">1.1<\/span> varnish\r\nContent-Length : 48918\r\n<span class=\"hljs-keyword\">Accept<\/span>-Ranges : <span class=\"hljs-type\">bytes<\/span>\r\nDate : <span class=\"hljs-type\">Fri<\/span>, <span class=\"hljs-number\">17<\/span> Apr <span class=\"hljs-number\">2020<\/span> <span class=\"hljs-number\">05<\/span>:<span class=\"hljs-number\">55<\/span>:<span class=\"hljs-number\">13<\/span> GMT\r\nAge : 1334\r\nConnection : <span class=\"hljs-type\">keep<\/span>-alive\r\nX-Served-By : <span class=\"hljs-type\">cache<\/span>-bwi5145-BWI, cache-dca17774-DCA\r\nX-Cache : <span class=\"hljs-type\">HIT<\/span>, HIT\r\nX-Cache-Hits : 3, 2\r\nX-Timer : <span class=\"hljs-type\">S1587102914.994481<\/span>,VS0,VE0\r\nVary : <span class=\"hljs-type\">Cookie<\/span>\r\nStrict-Transport-Security : <span class=\"hljs-type\">max<\/span>-age=<span class=\"hljs-number\">63072000<\/span>; includeSubDomains\r\n<\/code><\/pre>\r\n<p>As you can see, it gives information about the content type, last modified date, Age of the website etc.. You can access each one of these by considering the ouput from the function as dictionary.<\/p>\r\n<pre><code class=\"lang-python\">r<span class=\"hljs-selector-class\">.headers<\/span>[<span class=\"hljs-string\">'Content-Length'<\/span>]\r\n<\/code><\/pre>\r\n<pre><code><span class=\"hljs-symbol\">'48918<\/span>'\r\n<\/code><\/pre>\r\n<h2 id=\"advanced-functions\">Advanced Functions<\/h2>\r\n<p>Now as we have looked into the basics of the requests library, lets dive into some of the advanced functions From now onwards, I will be using the website &#8211; <a href=\"http:\/\/httpbin.org\/\">http:\/\/httpbin.org\/<\/a> to retrive as well as send and store information. Let&#8217;s try the commands that you have learned so far.<\/p>\r\n<h2 id=\"how-to-set-query-string-parameters\">How to Set Query String Parameters<\/h2>\r\n<p>Often the response given by the server differs based on the query you send. Like, you want to view the 2nd page of a 10 page article, instead of the first page.<\/p>\r\n<p>Or you want to search for a particular term in a website. In such cases, you will send additional parameters as part of the URL as a query. For example: <code>https:\/\/www.google.com\/search?q=babies<\/code> will return the search results of &#8216;babies&#8217;.<\/p>\r\n<p>Depending on the device you are using, location, referring source, user etc, these queries can easily get complicated. So instead of adding it in the url directly, using <code>requests.get()<\/code>, you can pass it as a separate parameter using the <code>params<\/code> argument. Let&#8217;s add couple of parameters to the query string, that is, <code>page=5<\/code> and <code>count=10<\/code> of <code>httpbin.org<\/code>.<\/p>\r\n<p>This essentially translates as &#8220;<a href=\"http:\/\/httpbin.org\/?page=5&amp;count=10\">http:\/\/httpbin.org\/?page=5&amp;count=10<\/a>&#8220;.<\/p>\r\n<pre><code class=\"lang-python\"># Setting parameters\r\nparameter= {<span class=\"hljs-string\">'page'<\/span>:<span class=\"hljs-number\">5<\/span> , <span class=\"hljs-string\">'count'<\/span>:<span class=\"hljs-number\">10<\/span>}\r\nr=requests.<span class=\"hljs-built_in\">get<\/span>(<span class=\"hljs-string\">'http:\/\/httpbin.org\/'<\/span>, params=parameter)\r\n<span class=\"hljs-built_in\">print<\/span>(r.<span class=\"hljs-built_in\">text<\/span>[:<span class=\"hljs-number\">600<\/span>])\r\n<\/code><\/pre>\r\n<pre><code><span class=\"hljs-meta\">&lt;!DOCTYPE html&gt;<\/span>\r\n<span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">html<\/span> <span class=\"hljs-attr\">lang<\/span>=<span class=\"hljs-string\">\"en\"<\/span>&gt;<\/span>\r\n\r\n<span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">head<\/span>&gt;<\/span>\r\n    <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">meta<\/span> <span class=\"hljs-attr\">charset<\/span>=<span class=\"hljs-string\">\"UTF-8\"<\/span>&gt;<\/span>\r\n    <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">title<\/span>&gt;<\/span>httpbin.org<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">title<\/span>&gt;<\/span>\r\n    <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">link<\/span> <span class=\"hljs-attr\">href<\/span>=<span class=\"hljs-string\">\"https:\/\/fonts.googleapis.com\/css?family=Open+Sans:400,700|Source+Code+Pro:300,600|Titillium+Web:400,600,700\"<\/span>\r\n        <span class=\"hljs-attr\">rel<\/span>=<span class=\"hljs-string\">\"stylesheet\"<\/span>&gt;<\/span>\r\n    <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">link<\/span> <span class=\"hljs-attr\">rel<\/span>=<span class=\"hljs-string\">\"stylesheet\"<\/span> <span class=\"hljs-attr\">type<\/span>=<span class=\"hljs-string\">\"text\/css\"<\/span> <span class=\"hljs-attr\">href<\/span>=<span class=\"hljs-string\">\"\/flasgger_static\/swagger-ui.css\"<\/span>&gt;<\/span>\r\n    <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">link<\/span> <span class=\"hljs-attr\">rel<\/span>=<span class=\"hljs-string\">\"icon\"<\/span> <span class=\"hljs-attr\">type<\/span>=<span class=\"hljs-string\">\"image\/png\"<\/span> <span class=\"hljs-attr\">href<\/span>=<span class=\"hljs-string\">\"\/static\/favicon.ico\"<\/span> <span class=\"hljs-attr\">sizes<\/span>=<span class=\"hljs-string\">\"64x64 32x32 16x16\"<\/span> \/&gt;<\/span>\r\n    <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">style<\/span>&gt;<\/span><span class=\"css\">\r\n        <span class=\"hljs-selector-tag\">html<\/span> {\r\n            <span class=\"hljs-attribute\">box-sizing<\/span>: border-box;\r\n            <span class=\"hljs-attribute\">overflow<\/span>: -moz-scrollbars-vertical;\r\n            <span class=\"hljs-attribute\">overflow-y<\/span>: scroll;\r\n        }\r\n\r\n        *,<\/span>\r\n<\/code><\/pre>\r\n<p>You can see that I have first created a dictionary for the parameters and then I passed it into the <code>get()<\/code> function. And we got a json response back from the httpbin website.<\/p>\r\n<p><strong>To check whether the parameter passing has worked properly, use <code>r.url<\/code> to check the parameters we have passed.<\/strong><\/p>\r\n<pre><code class=\"lang-python\"><span class=\"hljs-function\"><span class=\"hljs-title\">print<\/span><span class=\"hljs-params\">(r.url)<\/span><\/span>\r\n<\/code><\/pre>\r\n<pre><code><span class=\"hljs-symbol\">http:<\/span>\/\/httpbin<span class=\"hljs-meta\">.org<\/span>\/?page=<span class=\"hljs-number\">5<\/span>&amp;count=<span class=\"hljs-number\">10<\/span>\r\n<\/code><\/pre>\r\n<p>It has worked properly as the page is set to 5 and the count is set to 10. You can also pass it as a tuple or a byte which will give the same output.<\/p>\r\n<pre><code class=\"lang-python\"><span class=\"hljs-comment\"># Setting parameters<\/span>\r\nparameter= ((<span class=\"hljs-string\">'page'<\/span>,<span class=\"hljs-number\">5<\/span>) , (<span class=\"hljs-string\">'count'<\/span>,<span class=\"hljs-number\">10<\/span>))\r\nr=requests.<span class=\"hljs-built_in\">get<\/span>(<span class=\"hljs-string\">'http:\/\/httpbin.org\/'<\/span>, <span class=\"hljs-built_in\">params<\/span>=parameter)\r\nprint(r.<span class=\"hljs-keyword\">text<\/span>[:<span class=\"hljs-number\">400<\/span>])\r\n<\/code><\/pre>\r\n<pre><code><span class=\"hljs-meta\">&lt;!DOCTYPE html&gt;<\/span>\r\n<span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">html<\/span> <span class=\"hljs-attr\">lang<\/span>=<span class=\"hljs-string\">\"en\"<\/span>&gt;<\/span>\r\n\r\n<span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">head<\/span>&gt;<\/span>\r\n    <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">meta<\/span> <span class=\"hljs-attr\">charset<\/span>=<span class=\"hljs-string\">\"UTF-8\"<\/span>&gt;<\/span>\r\n    <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">title<\/span>&gt;<\/span>httpbin.org<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">title<\/span>&gt;<\/span>\r\n    <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">link<\/span> <span class=\"hljs-attr\">href<\/span>=<span class=\"hljs-string\">\"https:\/\/fonts.googleapis.com\/css?family=Open+Sans:400,700|Source+Code+Pro:300,600|Titillium+Web:400,600,700\"<\/span>\r\n        <span class=\"hljs-attr\">rel<\/span>=<span class=\"hljs-string\">\"stylesheet\"<\/span>&gt;<\/span>\r\n    <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">link<\/span> <span class=\"hljs-attr\">rel<\/span>=<span class=\"hljs-string\">\"stylesheet\"<\/span> <span class=\"hljs-attr\">type<\/span>=<span class=\"hljs-string\">\"text\/css\"<\/span> <span class=\"hljs-attr\">href<\/span>=<span class=\"hljs-string\">\"\/flasgger_static\/swagger-ui.css\"<\/span>&gt;<\/span>\r\n    <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">link<\/span> <span class=\"hljs-attr\">rel<\/span>=<span class=\"hljs-string\">\"icon\"<\/span> <span class=\"hljs-attr\">type<\/span>=<span class=\"hljs-string\">\"image\/png\"<\/span> <span class=\"hljs-attr\">href<\/span>=<span class=\"hljs-string\">\"\/static\/favicon.ico\"<\/span> <span class=\"hljs-attr\">si<\/span><\/span>\r\n<\/code><\/pre>\r\n<h2 id=\"post-method\">POST Method<\/h2>\r\n<p><strong>The POST method is used to submit data to be further handled by the server.<\/strong> The server typically understands the context and knows what to do with the data.<\/p>\r\n<p>Generally it&#8217;s used while submitting a web form or when uploading a file to the server. The <code>requests.post()<\/code> function allows you to do this. Let&#8217;s look into an example with <code>httpbin.org<\/code> website.<\/p>\r\n<pre><code class=\"lang-python\"><span class=\"hljs-comment\"># POST request<\/span>\r\nparam = { <span class=\"hljs-string\">'custname'<\/span>:<span class=\"hljs-string\">'abcd'<\/span>, <span class=\"hljs-string\">'custemail'<\/span>: <span class=\"hljs-string\">'efgh@gmail.com'<\/span>}\r\nr = requests.post(<span class=\"hljs-string\">'http:\/\/httpbin.org\/post'<\/span>, data=param)\r\n\r\n<span class=\"hljs-comment\"># As we are getting a json response, instead of using the text command, I am using json().<\/span>\r\npprint(r.json())\r\n<\/code><\/pre>\r\n<pre><code>{<span class=\"hljs-string\">'args'<\/span>: {},\r\n <span class=\"hljs-string\">'data'<\/span>: <span class=\"hljs-string\">''<\/span>,\r\n <span class=\"hljs-string\">'files'<\/span>: {},\r\n <span class=\"hljs-string\">'form'<\/span>: {<span class=\"hljs-string\">'custemail'<\/span>: <span class=\"hljs-string\">'efgh@gmail.com'<\/span>, <span class=\"hljs-string\">'custname'<\/span>: <span class=\"hljs-string\">'abcd'<\/span>},\r\n <span class=\"hljs-string\">'headers'<\/span>: {<span class=\"hljs-string\">'Accept'<\/span>: <span class=\"hljs-string\">'*\/*'<\/span>,\r\n             <span class=\"hljs-string\">'Accept-Encoding'<\/span>: <span class=\"hljs-string\">'gzip, deflate'<\/span>,\r\n             <span class=\"hljs-string\">'Content-Length'<\/span>: <span class=\"hljs-string\">'40'<\/span>,\r\n             <span class=\"hljs-string\">'Content-Type'<\/span>: <span class=\"hljs-string\">'application\/x-www-form-urlencoded'<\/span>,\r\n             <span class=\"hljs-string\">'Host'<\/span>: <span class=\"hljs-string\">'httpbin.org'<\/span>,\r\n             <span class=\"hljs-string\">'User-Agent'<\/span>: <span class=\"hljs-string\">'python-requests\/2.21.0'<\/span>,\r\n             <span class=\"hljs-string\">'X-Amzn-Trace-Id'<\/span>: <span class=\"hljs-string\">'Root=1-5e9c69e3-44d2f060dfeb7a401ffe7c28'<\/span>},\r\n <span class=\"hljs-string\">'json'<\/span>: None,\r\n <span class=\"hljs-string\">'origin'<\/span>: <span class=\"hljs-string\">'35.196.30.16'<\/span>,\r\n <span class=\"hljs-string\">'url'<\/span>: <span class=\"hljs-string\">'http:\/\/httpbin.org\/post'<\/span>}\r\n<\/code><\/pre>\r\n<p>You can see in the form type the <code>custname<\/code> and the <code>custemail<\/code> has been recorded. If you need to pass some form values into it, then you need to look into the source of the url and find out what kind of values the form expects.<\/p>\r\n<p>To process the received json response, iterate through the contents of <code>r.json()<\/code>.<\/p>\r\n<p>Or if you know what the contents, you can access it directly as you would with a <code>dict<\/code>.<\/p>\r\n<pre><code class=\"lang-python\"><span class=\"hljs-keyword\">for<\/span> k, v <span class=\"hljs-keyword\">in<\/span> r.json().items():\r\n  <span class=\"hljs-built_in\">print<\/span>(k, <span class=\"hljs-string\">\": \"<\/span>, v)\r\n<\/code><\/pre>\r\n<pre><code><span class=\"hljs-string\">args :<\/span>  {}\r\n<span class=\"hljs-string\">data :<\/span>  \r\n<span class=\"hljs-string\">files :<\/span>  {}\r\n<span class=\"hljs-string\">form :<\/span>  {<span class=\"hljs-string\">'custemail'<\/span>: <span class=\"hljs-string\">'efgh@gmail.com'<\/span>, <span class=\"hljs-string\">'custname'<\/span>: <span class=\"hljs-string\">'abcd'<\/span>}\r\n<span class=\"hljs-string\">headers :<\/span>  {<span class=\"hljs-string\">'Accept'<\/span>: <span class=\"hljs-string\">'*\/*'<\/span>, <span class=\"hljs-string\">'Accept-Encoding'<\/span>: <span class=\"hljs-string\">'gzip, deflate'<\/span>, <span class=\"hljs-string\">'Content-Length'<\/span>: <span class=\"hljs-string\">'40'<\/span>, <span class=\"hljs-string\">'Content-Type'<\/span>: <span class=\"hljs-string\">'application\/x-www-form-urlencoded'<\/span>, <span class=\"hljs-string\">'Host'<\/span>: <span class=\"hljs-string\">'httpbin.org'<\/span>, <span class=\"hljs-string\">'User-Agent'<\/span>: <span class=\"hljs-string\">'python-requests\/2.21.0'<\/span>, <span class=\"hljs-string\">'X-Amzn-Trace-Id'<\/span>: <span class=\"hljs-string\">'Root=1-5e9c69e3-44d2f060dfeb7a401ffe7c28'<\/span>}\r\n<span class=\"hljs-string\">json :<\/span>  None\r\n<span class=\"hljs-string\">origin :<\/span>  <span class=\"hljs-number\">35.196<\/span><span class=\"hljs-number\">.30<\/span><span class=\"hljs-number\">.16<\/span>\r\n<span class=\"hljs-string\">url :<\/span>  <span class=\"hljs-string\">http:<\/span><span class=\"hljs-comment\">\/\/httpbin.org\/post<\/span>\r\n<\/code><\/pre>\r\n<p>Post function can be used to send large amount of data (text \/ binary) data.<\/p>\r\n<h2 id=\"put-method\">PUT Method<\/h2>\r\n<p><strong>The PUT method requests that the data you are sending to be stored under the supplied URL.<\/strong> If the URL refers to an already existing resource, it is modified and if the URL does not point to an existing resource, then the server creates the resource with that URL. As you can see, the PUT is somewhat similar in functionality to POST.<\/p>\r\n<p>So what is the difference between PUT and POST? The difference is, the POST method sends data to a URI and the the receiving resource understands the context and knows how to handle the request. Whereas, in a PUT method, if there is a file in the given URI, it gets replaced. And if there isn&#8217;t any, a file is created.<\/p>\r\n<p>Besides, not matter how many times you execute a given PUT request, the resulting action is always the same. This property is called idempotence. Whereas, for a POST method, the response need not always be the same. This makes the PUT method idempotent and the POST method is not. To make a PUT request, use the <code>requests.put()<\/code> method.<\/p>\r\n<pre><code class=\"lang-python\">import requests \r\nr = requests.put(<span class=\"hljs-string\">'https:\/\/httpbin.org\/put'<\/span>, data ={<span class=\"hljs-string\">'name'<\/span>:<span class=\"hljs-string\">'abcd'<\/span>})\r\n<span class=\"hljs-function\"><span class=\"hljs-title\">print<\/span><span class=\"hljs-params\">(r)<\/span><\/span> \r\n<span class=\"hljs-function\"><span class=\"hljs-title\">print<\/span><span class=\"hljs-params\">(r.content)<\/span><\/span>\r\n<\/code><\/pre>\r\n<pre><code>&lt;<span class=\"hljs-type\">Response<\/span> [<span class=\"hljs-number\">200<\/span>]&gt;\r\nb'{\\n  <span class=\"hljs-string\">\"args\"<\/span>: {}, \\n  <span class=\"hljs-string\">\"data\"<\/span>: <span class=\"hljs-string\">\"\"<\/span>, \\n  <span class=\"hljs-string\">\"files\"<\/span>: {}, \\n  <span class=\"hljs-string\">\"form\"<\/span>: {\\n    <span class=\"hljs-string\">\"name\"<\/span>: <span class=\"hljs-string\">\"abcd\"<\/span>\\n  }, \\n  <span class=\"hljs-string\">\"headers\"<\/span>: {\\n    <span class=\"hljs-string\">\"Accept\"<\/span>: <span class=\"hljs-string\">\"*\/*\"<\/span>, \\n    <span class=\"hljs-string\">\"Accept-Encoding\"<\/span>: <span class=\"hljs-string\">\"gzip, deflate\"<\/span>, \\n    <span class=\"hljs-string\">\"Content-Length\"<\/span>: <span class=\"hljs-string\">\"9\"<\/span>, \\n    <span class=\"hljs-string\">\"Content-Type\"<\/span>: <span class=\"hljs-string\">\"application\/x-www-form-urlencoded\"<\/span>, \\n    <span class=\"hljs-string\">\"Host\"<\/span>: <span class=\"hljs-string\">\"httpbin.org\"<\/span>, \\n    <span class=\"hljs-string\">\"User-Agent\"<\/span>: <span class=\"hljs-string\">\"python-requests\/2.21.0\"<\/span>, \\n    <span class=\"hljs-string\">\"X-Amzn-Trace-Id\"<\/span>: <span class=\"hljs-string\">\"Root=1-5e997c61-9382102be4038f1b7f1352d0\"<\/span>\\n  }, \\n  <span class=\"hljs-string\">\"json\"<\/span>: null, \\n  <span class=\"hljs-string\">\"origin\"<\/span>: <span class=\"hljs-string\">\"35.221.187.164\"<\/span>, \\n  <span class=\"hljs-string\">\"url\"<\/span>: <span class=\"hljs-string\">\"https:\/\/httpbin.org\/put\"<\/span>\\n}\\n'\r\n<\/code><\/pre>\r\n<p>Generally in practice, <code>put()<\/code> function is used for updating operations and <code>post()<\/code> function is used for creating operations.<\/p>\r\n<h2 id=\"delete-method\">DELETE Method<\/h2>\r\n<p>The delete() method sends a DELETE request to the specified url. DELETE requests are made for deleting the specified resource (file, record etc). A successful response should be:<\/p>\r\n<ol>\r\n<li><strong>200 (OK)<\/strong> if the response includes an entity describing the status.<\/li>\r\n<li><strong>202 (Accepted)<\/strong> if the action has not yet been enacted<\/li>\r\n<li><strong>204 (No Content)<\/strong> if the action has been enacted but the response does not include an entity.<\/li>\r\n<\/ol>\r\n<pre><code class=\"lang-python\">import requests \r\nr = requests.delete(<span class=\"hljs-string\">'https:\/\/httpbin.org\/delete'<\/span>, data ={<span class=\"hljs-string\">'name'<\/span>:<span class=\"hljs-string\">'abcd'<\/span>}) \r\n<span class=\"hljs-function\"><span class=\"hljs-title\">print<\/span><span class=\"hljs-params\">(r)<\/span><\/span> \r\n<span class=\"hljs-function\"><span class=\"hljs-title\">print<\/span><span class=\"hljs-params\">(r.json()<\/span><\/span>)\r\n<\/code><\/pre>\r\n<pre><code>&lt;Response [<span class=\"hljs-number\">200<\/span>]&gt;\r\n{<span class=\"hljs-string\">'args'<\/span>: {}, <span class=\"hljs-string\">'data'<\/span>: <span class=\"hljs-string\">''<\/span>, <span class=\"hljs-string\">'files'<\/span>: {}, <span class=\"hljs-string\">'form'<\/span>: {<span class=\"hljs-string\">'name'<\/span>: <span class=\"hljs-string\">'abcd'<\/span>}, <span class=\"hljs-string\">'headers'<\/span>: {<span class=\"hljs-string\">'Accept'<\/span>: <span class=\"hljs-string\">'*\/*'<\/span>, <span class=\"hljs-string\">'Accept-Encoding'<\/span>: <span class=\"hljs-string\">'gzip, deflate'<\/span>, <span class=\"hljs-string\">'Content-Length'<\/span>: <span class=\"hljs-string\">'9'<\/span>, <span class=\"hljs-string\">'Content-Type'<\/span>: <span class=\"hljs-string\">'application\/x-www-form-urlencoded'<\/span>, <span class=\"hljs-string\">'Host'<\/span>: <span class=\"hljs-string\">'httpbin.org'<\/span>, <span class=\"hljs-string\">'User-Agent'<\/span>: <span class=\"hljs-string\">'python-requests\/2.21.0'<\/span>, <span class=\"hljs-string\">'X-Amzn-Trace-Id'<\/span>: <span class=\"hljs-string\">'Root=1-5e997dff-2b42c5cf3ebe64c9d60fa8a8'<\/span>}, <span class=\"hljs-string\">'json'<\/span>: None, <span class=\"hljs-string\">'origin'<\/span>: <span class=\"hljs-string\">'35.221.187.164'<\/span>, <span class=\"hljs-string\">'url'<\/span>: <span class=\"hljs-string\">'https:\/\/httpbin.org\/delete'<\/span>}\r\n<\/code><\/pre>\r\n<p>The <code>delete()<\/code> function will request the server to delete a resource that you have specified in the URL. The client, however, cannot be guaranteed that the operation has been carried out.<\/p>\r\n<h2 id=\"patch-method\">PATCH Method<\/h2>\r\n<p><strong>The PATCH method is a request method supported by the HTTP protocol for making partial changes to an existing resource.<\/strong> The <strong>main difference between the PUT and PATCH method is that the PUT method uses the request URL to supply a modified version of the requested resource.<\/strong><\/p>\r\n<p>And it replaces the original version of the resource. Whereas, the PATCH method only supplies a set of instructions to modify the resource. This means, the PATCH request needs to contain only the changes that needs to be applied to a resource and not the entire resource. Although it resembles PUT, it typically contains a set of instructions that tell how a resource residing at a URI should be modified to produce a new version. Use the <code>requests.patch()<\/code> command to implement this. So when to use PATCH? Whenever you want to make only partial changes to the resource.<\/p>\r\n<pre><code class=\"lang-python\">import requests \r\nr = requests.patch(<span class=\"hljs-string\">'https:\/\/httpbin.org\/patch'<\/span>, data ={<span class=\"hljs-string\">'name'<\/span>:<span class=\"hljs-string\">'abcd'<\/span>}) \r\n<span class=\"hljs-function\"><span class=\"hljs-title\">print<\/span><span class=\"hljs-params\">(r)<\/span><\/span> \r\n<span class=\"hljs-function\"><span class=\"hljs-title\">pprint<\/span><span class=\"hljs-params\">(r.json()<\/span><\/span>)\r\n<\/code><\/pre>\r\n<pre><code>&lt;Response [<span class=\"hljs-number\">200<\/span>]&gt;\r\n{<span class=\"hljs-string\">'args'<\/span>: {},\r\n <span class=\"hljs-string\">'data'<\/span>: <span class=\"hljs-string\">''<\/span>,\r\n <span class=\"hljs-string\">'files'<\/span>: {},\r\n <span class=\"hljs-string\">'form'<\/span>: {<span class=\"hljs-string\">'name'<\/span>: <span class=\"hljs-string\">'abcd'<\/span>},\r\n <span class=\"hljs-string\">'headers'<\/span>: {<span class=\"hljs-string\">'Accept'<\/span>: <span class=\"hljs-string\">'*\/*'<\/span>,\r\n             <span class=\"hljs-string\">'Accept-Encoding'<\/span>: <span class=\"hljs-string\">'gzip, deflate'<\/span>,\r\n             <span class=\"hljs-string\">'Content-Length'<\/span>: <span class=\"hljs-string\">'9'<\/span>,\r\n             <span class=\"hljs-string\">'Content-Type'<\/span>: <span class=\"hljs-string\">'application\/x-www-form-urlencoded'<\/span>,\r\n             <span class=\"hljs-string\">'Host'<\/span>: <span class=\"hljs-string\">'httpbin.org'<\/span>,\r\n             <span class=\"hljs-string\">'User-Agent'<\/span>: <span class=\"hljs-string\">'python-requests\/2.21.0'<\/span>,\r\n             <span class=\"hljs-string\">'X-Amzn-Trace-Id'<\/span>: <span class=\"hljs-string\">'Root=1-5e9c6fd2-fea9a805120b3ab9b59bf62a'<\/span>},\r\n <span class=\"hljs-string\">'json'<\/span>: None,\r\n <span class=\"hljs-string\">'origin'<\/span>: <span class=\"hljs-string\">'35.196.30.16'<\/span>,\r\n <span class=\"hljs-string\">'url'<\/span>: <span class=\"hljs-string\">'https:\/\/httpbin.org\/patch'<\/span>}\r\n<\/code><\/pre>\r\n<h2 id=\"head-method\">HEAD Method<\/h2>\r\n<p><strong><code>head()<\/code> function is useful for retrieving only the meta-information written in response headers<\/strong>, without having to transport the entire content like the <code>get()<\/code> command.<\/p>\r\n<p>This method is often used for testing hypertext links for validity, accessibility, and recent modification. You can do this by using the <code>requests.head()<\/code> command with the web address and data as argument.<\/p>\r\n<pre><code class=\"lang-python\">import requests \r\nr = requests.head(<span class=\"hljs-string\">'https:\/\/httpbin.org\/'<\/span>, data ={<span class=\"hljs-string\">'key'<\/span>:<span class=\"hljs-string\">'value'<\/span>}) \r\n<span class=\"hljs-function\"><span class=\"hljs-title\">print<\/span><span class=\"hljs-params\">(r)<\/span><\/span> \r\n<span class=\"hljs-function\"><span class=\"hljs-title\">print<\/span><span class=\"hljs-params\">(r.headers)<\/span><\/span> \r\n<span class=\"hljs-function\"><span class=\"hljs-title\">pprint<\/span><span class=\"hljs-params\">(r.text)<\/span><\/span>\r\n<\/code><\/pre>\r\n<pre><code>&lt;<span class=\"hljs-symbol\">Response<\/span> [<span class=\"hljs-number\">200<\/span>]&gt;\r\n{<span class=\"hljs-string\">'Date'<\/span>: <span class=\"hljs-string\">'Sun, 19 Apr 2020 15:45:25 GMT'<\/span>, <span class=\"hljs-string\">'Content-Type'<\/span>: <span class=\"hljs-string\">'text\/html; charset=utf-8'<\/span>, <span class=\"hljs-string\">'Content-Length'<\/span>: <span class=\"hljs-string\">'9593'<\/span>, <span class=\"hljs-string\">'Connection'<\/span>: <span class=\"hljs-string\">'keep-alive'<\/span>, <span class=\"hljs-string\">'Server'<\/span>: <span class=\"hljs-string\">'gunicorn\/19.9.0'<\/span>, <span class=\"hljs-string\">'Access-Control-Allow-Origin'<\/span>: <span class=\"hljs-string\">'*'<\/span>, <span class=\"hljs-string\">'Access-Control-Allow-Credentials'<\/span>: <span class=\"hljs-string\">'true'<\/span>}\r\n<span class=\"hljs-string\">''<\/span>\r\n<\/code><\/pre>\r\n<p>Let&#8217;s run the same as a GET request and see the difference.<\/p>\r\n<pre><code class=\"lang-python\">r = requests.get(<span class=\"hljs-string\">'https:\/\/httpbin.org\/'<\/span>, data ={<span class=\"hljs-string\">'key'<\/span>:<span class=\"hljs-string\">'value'<\/span>}) \r\n<span class=\"hljs-function\"><span class=\"hljs-title\">print<\/span><span class=\"hljs-params\">(r)<\/span><\/span> \r\n<span class=\"hljs-function\"><span class=\"hljs-title\">print<\/span><span class=\"hljs-params\">(r.headers)<\/span><\/span> \r\n<span class=\"hljs-function\"><span class=\"hljs-title\">pprint<\/span><span class=\"hljs-params\">(r.text[:<span class=\"hljs-number\">500<\/span>])<\/span><\/span>\r\n<\/code><\/pre>\r\n<pre><code>&lt;Response [<span class=\"hljs-number\">200<\/span>]&gt;\r\n{<span class=\"hljs-string\">'Date'<\/span>: <span class=\"hljs-string\">'Sun, 19 Apr 2020 15:49:24 GMT'<\/span>, <span class=\"hljs-string\">'Content-Type'<\/span>: <span class=\"hljs-string\">'text\/html; charset=utf-8'<\/span>, <span class=\"hljs-string\">'Content-Length'<\/span>: <span class=\"hljs-string\">'9593'<\/span>, <span class=\"hljs-string\">'Connection'<\/span>: <span class=\"hljs-string\">'keep-alive'<\/span>, <span class=\"hljs-string\">'Server'<\/span>: <span class=\"hljs-string\">'gunicorn\/19.9.0'<\/span>, <span class=\"hljs-string\">'Access-Control-Allow-Origin'<\/span>: <span class=\"hljs-string\">'*'<\/span>, <span class=\"hljs-string\">'Access-Control-Allow-Credentials'<\/span>: <span class=\"hljs-string\">'true'<\/span>}\r\n(<span class=\"hljs-string\">'&lt;!DOCTYPE html&gt;\\n'<\/span>\r\n <span class=\"hljs-string\">'&lt;html lang=\"<\/span>en<span class=\"hljs-string\">\"&gt;\\n'<\/span>\r\n <span class=\"hljs-string\">'\\n'<\/span>\r\n <span class=\"hljs-string\">'&lt;head&gt;\\n'<\/span>\r\n <span class=\"hljs-string\">'    &lt;meta charset=\"<\/span>UTF<span class=\"hljs-number\">-8<\/span><span class=\"hljs-string\">\"&gt;\\n'<\/span>\r\n <span class=\"hljs-string\">'    &lt;title&gt;httpbin.org&lt;\/title&gt;\\n'<\/span>\r\n <span class=\"hljs-string\">'    &lt;link '<\/span>\r\n <span class=\"hljs-string\">'href=\"<\/span>https:<span class=\"hljs-comment\">\/\/fonts.googleapis.com\/css?family=Open+Sans:400,700|Source+Code+Pro:300,600|Titillium+Web:400,600,700\"\\n'<\/span>\r\n <span class=\"hljs-string\">'        rel=\"<\/span>stylesheet<span class=\"hljs-string\">\"&gt;\\n'<\/span>\r\n <span class=\"hljs-string\">'    &lt;link rel=\"<\/span>stylesheet<span class=\"hljs-string\">\" type=\"<\/span>text\/css<span class=\"hljs-string\">\" '<\/span>\r\n <span class=\"hljs-string\">'href=\"<\/span>\/flasgger_static\/swagger-ui.css<span class=\"hljs-string\">\"&gt;\\n'<\/span>\r\n <span class=\"hljs-string\">'    &lt;link rel=\"<\/span>icon<span class=\"hljs-string\">\" type=\"<\/span>image\/png<span class=\"hljs-string\">\" href=\"<\/span>\/static\/favicon.ico<span class=\"hljs-string\">\" '<\/span>\r\n <span class=\"hljs-string\">'sizes=\"<\/span><span class=\"hljs-number\">64<\/span>x64 <span class=\"hljs-number\">32<\/span>x32 <span class=\"hljs-number\">16<\/span>x16<span class=\"hljs-string\">\" \/&gt;\\n'<\/span>\r\n <span class=\"hljs-string\">'    &lt;style&gt;\\n'<\/span>\r\n <span class=\"hljs-string\">'        html {\\n'<\/span>\r\n <span class=\"hljs-string\">'            box-sizing: border-box;\\n'<\/span>\r\n <span class=\"hljs-string\">'          '<\/span>)\r\n<\/code><\/pre>\r\n<p>Notice, we received only header content with <code>requests.head()<\/code>. Rest of the content is ignored. So, it will save time and resource if you are interested only in the header content.<\/p>\r\n<h2 id=\"request-header\">Request Header<\/h2>\r\n<p><strong>A request header is an HTTP header that can be used in an HTTP request, and that doesn&#8217;t relate to the content of the message.<\/strong><\/p>\r\n<p>To customize headers, you pass a dictionary of HTTP headers to <code>get()<\/code> using the <code>headers<\/code> parameter. Through the &#8216;Accept&#8217; header, the client tells the server what content types your application can handle.<\/p>\r\n<pre><code class=\"lang-python\"><span class=\"hljs-keyword\">import<\/span> requests\r\nr=requests.<span class=\"hljs-built_in\">get<\/span>(<span class=\"hljs-string\">\"http:\/\/www.example.com\/\"<\/span>, headers={<span class=\"hljs-string\">'Accept'<\/span>: <span class=\"hljs-string\">'application\/qrd.github.v1.text+json'<\/span>})\r\nr\r\n<\/code><\/pre>\r\n<pre><code>&lt;Response <span class=\"hljs-string\">[200]<\/span>&gt;\r\n<\/code><\/pre>\r\n<h2 id=\"inspecting-the-request-made\">Inspecting the request made<\/h2>\r\n<p>When you make a request, the requests library prepares the request before actually sending it to the destination server. <strong>Request preparation includes things like validating headers and serializing JSON content.<\/strong><\/p>\r\n<p>Only after preparing the request, the request will be sent to the destination server. You can view the PreparedRequest by accessing the json.<\/p>\r\n<pre><code class=\"lang-python\"><span class=\"hljs-comment\"># Inspect the URL<\/span>\r\nparam= { <span class=\"hljs-string\">'username'<\/span>:<span class=\"hljs-string\">'abcd'<\/span>, <span class=\"hljs-string\">'password'<\/span>: <span class=\"hljs-string\">'efgh'<\/span>}\r\n\r\n<span class=\"hljs-comment\"># We are passing this param as the data<\/span>\r\nr=requests.post(<span class=\"hljs-string\">'http:\/\/httpbin.org\/post'<\/span>,data=param)\r\nr.request.url\r\n<\/code><\/pre>\r\n<pre><code><span class=\"hljs-symbol\">'http<\/span>:<span class=\"hljs-comment\">\/\/httpbin.org\/post'<\/span>\r\n<\/code><\/pre>\r\n<p>This helps you in getting access to informations like payload, URL, headers, authentication, and more.<\/p>\r\n<pre><code class=\"lang-python\"><span class=\"hljs-comment\"># Inspect the Parameters<\/span>\r\nparam= { <span class=\"hljs-string\">'username'<\/span>:<span class=\"hljs-string\">'abcd'<\/span>, <span class=\"hljs-string\">'password'<\/span>: <span class=\"hljs-string\">'efgh'<\/span>}\r\nr=requests.post(<span class=\"hljs-string\">'http:\/\/httpbin.org\/post'<\/span>,data=param)\r\n\r\n<span class=\"hljs-comment\"># As we are getting a json resposne, instead of using the text command, I am using json().<\/span>\r\n<span class=\"hljs-keyword\">dict<\/span>=r.json()\r\nprint(<span class=\"hljs-keyword\">dict<\/span>[<span class=\"hljs-string\">'form'<\/span>])\r\n<\/code><\/pre>\r\n<pre><code>{<span class=\"hljs-string\">'password'<\/span>: <span class=\"hljs-string\">'efgh'<\/span>, <span class=\"hljs-string\">'username'<\/span>: <span class=\"hljs-string\">'abcd'<\/span>}\r\n<\/code><\/pre>\r\n<p>You can see that I have stored the ouput of the <code>r.json<\/code> in a dictionary and I can accesing different information from the dictionary separately.<\/p>\r\n<h2 id=\"authentication\">Authentication<\/h2>\r\n<p><strong>Authentication helps a service understand who you are.<\/strong> You provide your credentials to a server by passing data through the Authorization header or a custom header defined by the service. You need to use the <code>auth<\/code> command to do this.<\/p>\r\n<pre><code class=\"lang-python\">r= requests.<span class=\"hljs-built_in\">get<\/span>(<span class=\"hljs-string\">'http:\/\/httpbin.org\/basic-auth\/abcd\/efgh'<\/span>, auth=(<span class=\"hljs-string\">'abcd'<\/span>,<span class=\"hljs-string\">'efgh'<\/span>))\r\n<span class=\"hljs-built_in\">print<\/span>(r.<span class=\"hljs-built_in\">text<\/span>)\r\n<\/code><\/pre>\r\n<pre><code>{\r\n  <span class=\"hljs-attr\">\"authenticated\"<\/span>: <span class=\"hljs-literal\">true<\/span>, \r\n  <span class=\"hljs-attr\">\"user\"<\/span>: <span class=\"hljs-string\">\"abcd\"<\/span>\r\n}\r\n<\/code><\/pre>\r\n<p>What we are doing is we are giving our data to the server by passing data through the <code>authorization<\/code> header. <strong>If we go into the <code>httpbins<\/code> website, you can see that the basic authentication format for the website is of the form <code>http:\/\/httpbin.org\/basic-auth\/username\/password<\/code>.<\/strong> In this the <code>username<\/code> and <code>password<\/code> will be what we have specified.<\/p>\r\n<p>The authentication output comes out to be &#8216;true&#8217; which means that our username and password is correct. If our password is wrong, we wont be getting any output for authentication.<\/p>\r\n<pre><code class=\"lang-python\">r= requests.get(<span class=\"hljs-string\">'http:\/\/httpbin.org\/basic-auth\/abcd\/efgh'<\/span>, auth=(<span class=\"hljs-string\">'abcdfgh'<\/span>,<span class=\"hljs-string\">'efgh'<\/span>))\r\n<span class=\"hljs-function\"><span class=\"hljs-title\">print<\/span><span class=\"hljs-params\">(r)<\/span><\/span>\r\n<\/code><\/pre>\r\n<pre><code>&lt;Response <span class=\"hljs-string\">[401]<\/span>&gt;\r\n<\/code><\/pre>\r\n<p>You can see that if I use the wrong username, I am getting an 401 error. When you pass your username and password in a tuple to the auth parameter, requests is applying the credentials using HTTP\u00e2\u20ac\u2122s Basic access authentication scheme under the hood.<\/p>\r\n<h2 id=\"time-out\">Time out<\/h2>\r\n<p>When you send a request to a server, your system typically waits for a certain amount of time for the other server to respond. If this takes too much times, then there is a possibility that your system will hang.<\/p>\r\n<p><strong>Time-out is set to make sure that the if the website is not responding for a certain amount of time it has to stop loading.<\/strong> If we dont set the timeout then the website will be loading forever if the server is not responding. Use the <code>timeout=<\/code> command to set the time limit in seconds.<\/p>\r\n<pre><code class=\"lang-python\"><span class=\"hljs-attr\">r<\/span>= requests.get(<span class=\"hljs-string\">'http:\/\/httpbin.org\/basic-auth\/abcd\/efgh'<\/span>, timeout=<span class=\"hljs-number\">5<\/span>)\r\n<\/code><\/pre>\r\n<p>In the above case, I have set the time limit to 5 seconds.<\/p>\r\n<p>You can also pass a tuple to timeout with the first element being a <strong>connect timeout<\/strong> (the timeout allows for the client to establish a connection to the server), and the second being a <strong>read timeout<\/strong> (the time it will wait on a response once your client has established a connection):<\/p>\r\n<pre><code class=\"lang-python\"><span class=\"hljs-attr\">r<\/span>=requests.get(<span class=\"hljs-string\">'http:\/\/httpbin.org\/basic-auth\/abcd\/efgh'<\/span>, timeout=(<span class=\"hljs-number\">3<\/span>,<span class=\"hljs-number\">7<\/span>))\r\n<\/code><\/pre>\r\n<p>This means that the request should establish a connection with server before 3 seconds and the data must be recieved within 7 seconds after the connection is established.<\/p>\r\n<p>If the request times out, then the function will raise a Timeout exception. You can handle this exception as well by importing <code>Timeout<\/code> from <code>requests.exceptions<\/code>.<\/p>\r\n<pre><code class=\"lang-python\"><span class=\"hljs-keyword\">from<\/span> requests.exceptions <span class=\"hljs-keyword\">import<\/span> Timeout\r\n\r\n<span class=\"hljs-keyword\">try<\/span>:\r\n    response = requests.get(<span class=\"hljs-string\">'http:\/\/httpbin.org\/basic-auth\/abcd\/efgh'<\/span>, timeout=<span class=\"hljs-number\">1<\/span>)\r\n<span class=\"hljs-keyword\">except<\/span> Timeout:\r\n    print(<span class=\"hljs-string\">'Request timed out'<\/span>)\r\n<span class=\"hljs-keyword\">else<\/span>:\r\n    print(<span class=\"hljs-string\">'Request went through'<\/span>)\r\n<\/code><\/pre>\r\n<h2 id=\"ssl-certificate-vertification\">SSL Certificate Vertification<\/h2>\r\n<p><strong>SSL Certificates are small data files that digitally bind a cryptographic key to an organization\u00e2\u20ac\u2122s detail.<\/strong> An <strong>organization needs to install the SSL Certificate onto its web server to initiate a secure session with browsers<\/strong>.<\/p>\r\n<p>Once a secure connection is established, all web traffic between the web server and the web browser will be secure. If the data you are trying to receive or send is sensitive, then it is done by establishing a encrypted connection using SSL. requests library does this for you by default. If you don&#8217;t want to do this, then we can set the paramter verify to be false in the <code>get()<\/code> function.<\/p>\r\n<pre><code class=\"lang-python\">requests.get(<span class=\"hljs-symbol\">'http<\/span>:\/\/httpbin.org\/basic-auth\/abcd\/efgh', verify=<span class=\"hljs-literal\">False<\/span>)\r\n<\/code><\/pre>\r\n<pre><code>&lt;Response <span class=\"hljs-string\">[401]<\/span>&gt;\r\n<\/code><\/pre>","protected":false},"excerpt":{"rendered":"<p>Requests is an elegant and simple Python library built to handle HTTP requests in python easily. It allows you make GET, POST, PUT and other types of requests and process the received response in a flexible Pythonic way. Contents Introduction to Requests Library What is a GET and POST request? GET Method Status Code Contents [&hellip;]<\/p>\n","protected":false},"author":7,"featured_media":3490,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"site-sidebar-layout":"default","site-content-layout":"default","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"default","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[21],"tags":[98,22,97],"class_list":["post-2690","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-python","tag-http","tag-python","tag-requests"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Requests in Python Tutorial - How to send HTTP requests in Python? - machinelearningplus<\/title>\n<meta name=\"description\" content=\"Learn how to send HTTP requests in Python using the Requests library. Covers GET, POST, PUT, DELETE methods, headers, parameters, and response handling.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/machinelearningplus.com\/python\/requests-in-python\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Requests in Python Tutorial - How to send HTTP requests in Python? - machinelearningplus\" \/>\n<meta property=\"og:description\" content=\"Learn how to send HTTP requests in Python using the Requests library. Covers GET, POST, PUT, DELETE methods, headers, parameters, and response handling.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/machinelearningplus.com\/python\/requests-in-python\/\" \/>\n<meta property=\"og:site_name\" content=\"machinelearningplus\" \/>\n<meta property=\"article:published_time\" content=\"2020-04-18T11:22:12+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-10-10T11:16:43+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/machinelearningplus.com\/wp-content\/uploads\/2020\/04\/MACHINE-LEARNING-PLUS-A-Complete-Beginners-Guide-to-SQLite-IN-Python-3.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1280\" \/>\n\t<meta property=\"og:image:height\" content=\"720\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Venmani A D\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Venmani A D\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"21 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"TechArticle\",\"@id\":\"https:\\\/\\\/machinelearningplus.com\\\/python\\\/requests-in-python\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/machinelearningplus.com\\\/python\\\/requests-in-python\\\/\"},\"author\":{\"name\":\"Venmani A D\",\"@id\":\"https:\\\/\\\/machinelearningplus.com\\\/#\\\/schema\\\/person\\\/5496cd92445387e04c3ee0737a78efa0\"},\"headline\":\"Requests in Python Tutorial &#8211; How to send HTTP requests in Python?\",\"datePublished\":\"2020-04-18T11:22:12+00:00\",\"dateModified\":\"2022-10-10T11:16:43+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/machinelearningplus.com\\\/python\\\/requests-in-python\\\/\"},\"wordCount\":2867,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/machinelearningplus.com\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/machinelearningplus.com\\\/python\\\/requests-in-python\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/machinelearningplus.com\\\/wp-content\\\/uploads\\\/2020\\\/04\\\/MACHINE-LEARNING-PLUS-A-Complete-Beginners-Guide-to-SQLite-IN-Python-3.png\",\"keywords\":[\"HTTP\",\"Python\",\"Requests\"],\"articleSection\":[\"Python\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/machinelearningplus.com\\\/python\\\/requests-in-python\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/machinelearningplus.com\\\/python\\\/requests-in-python\\\/\",\"url\":\"https:\\\/\\\/machinelearningplus.com\\\/python\\\/requests-in-python\\\/\",\"name\":\"Requests in Python Tutorial - How to send HTTP requests in Python? - machinelearningplus\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/machinelearningplus.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/machinelearningplus.com\\\/python\\\/requests-in-python\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/machinelearningplus.com\\\/python\\\/requests-in-python\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/machinelearningplus.com\\\/wp-content\\\/uploads\\\/2020\\\/04\\\/MACHINE-LEARNING-PLUS-A-Complete-Beginners-Guide-to-SQLite-IN-Python-3.png\",\"datePublished\":\"2020-04-18T11:22:12+00:00\",\"dateModified\":\"2022-10-10T11:16:43+00:00\",\"description\":\"Learn how to send HTTP requests in Python using the Requests library. Covers GET, POST, PUT, DELETE methods, headers, parameters, and response handling.\",\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/machinelearningplus.com\\\/python\\\/requests-in-python\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/machinelearningplus.com\\\/python\\\/requests-in-python\\\/#primaryimage\",\"url\":\"https:\\\/\\\/machinelearningplus.com\\\/wp-content\\\/uploads\\\/2020\\\/04\\\/MACHINE-LEARNING-PLUS-A-Complete-Beginners-Guide-to-SQLite-IN-Python-3.png\",\"contentUrl\":\"https:\\\/\\\/machinelearningplus.com\\\/wp-content\\\/uploads\\\/2020\\\/04\\\/MACHINE-LEARNING-PLUS-A-Complete-Beginners-Guide-to-SQLite-IN-Python-3.png\",\"width\":1280,\"height\":720},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/machinelearningplus.com\\\/#website\",\"url\":\"https:\\\/\\\/machinelearningplus.com\\\/\",\"name\":\"machinelearningplus\",\"description\":\"Learn Data Science (AI \\\/ ML) Online\",\"publisher\":{\"@id\":\"https:\\\/\\\/machinelearningplus.com\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/machinelearningplus.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/machinelearningplus.com\\\/#organization\",\"name\":\"machinelearningplus\",\"url\":\"https:\\\/\\\/machinelearningplus.com\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/machinelearningplus.com\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/machinelearningplus.com\\\/wp-content\\\/uploads\\\/2022\\\/05\\\/MachineLearningplus-logo.svg\",\"contentUrl\":\"https:\\\/\\\/machinelearningplus.com\\\/wp-content\\\/uploads\\\/2022\\\/05\\\/MachineLearningplus-logo.svg\",\"width\":348,\"height\":36,\"caption\":\"machinelearningplus\"},\"image\":{\"@id\":\"https:\\\/\\\/machinelearningplus.com\\\/#\\\/schema\\\/logo\\\/image\\\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/machinelearningplus.com\\\/#\\\/schema\\\/person\\\/5496cd92445387e04c3ee0737a78efa0\",\"name\":\"Venmani A D\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/machinelearningplus.com\\\/wp-content\\\/litespeed\\\/avatar\\\/d1b80494908c2c820cbd96a6a804f163.jpg?ver=1776364784\",\"url\":\"https:\\\/\\\/machinelearningplus.com\\\/wp-content\\\/litespeed\\\/avatar\\\/d1b80494908c2c820cbd96a6a804f163.jpg?ver=1776364784\",\"contentUrl\":\"https:\\\/\\\/machinelearningplus.com\\\/wp-content\\\/litespeed\\\/avatar\\\/d1b80494908c2c820cbd96a6a804f163.jpg?ver=1776364784\",\"caption\":\"Venmani A D\"},\"url\":\"https:\\\/\\\/machinelearningplus.com\\\/author\\\/venmani\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Requests in Python Tutorial - How to send HTTP requests in Python? - machinelearningplus","description":"Learn how to send HTTP requests in Python using the Requests library. Covers GET, POST, PUT, DELETE methods, headers, parameters, and response handling.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/machinelearningplus.com\/python\/requests-in-python\/","og_locale":"en_US","og_type":"article","og_title":"Requests in Python Tutorial - How to send HTTP requests in Python? - machinelearningplus","og_description":"Learn how to send HTTP requests in Python using the Requests library. Covers GET, POST, PUT, DELETE methods, headers, parameters, and response handling.","og_url":"https:\/\/machinelearningplus.com\/python\/requests-in-python\/","og_site_name":"machinelearningplus","article_published_time":"2020-04-18T11:22:12+00:00","article_modified_time":"2022-10-10T11:16:43+00:00","og_image":[{"width":1280,"height":720,"url":"https:\/\/machinelearningplus.com\/wp-content\/uploads\/2020\/04\/MACHINE-LEARNING-PLUS-A-Complete-Beginners-Guide-to-SQLite-IN-Python-3.png","type":"image\/png"}],"author":"Venmani A D","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Venmani A D","Est. reading time":"21 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"TechArticle","@id":"https:\/\/machinelearningplus.com\/python\/requests-in-python\/#article","isPartOf":{"@id":"https:\/\/machinelearningplus.com\/python\/requests-in-python\/"},"author":{"name":"Venmani A D","@id":"https:\/\/machinelearningplus.com\/#\/schema\/person\/5496cd92445387e04c3ee0737a78efa0"},"headline":"Requests in Python Tutorial &#8211; How to send HTTP requests in Python?","datePublished":"2020-04-18T11:22:12+00:00","dateModified":"2022-10-10T11:16:43+00:00","mainEntityOfPage":{"@id":"https:\/\/machinelearningplus.com\/python\/requests-in-python\/"},"wordCount":2867,"commentCount":0,"publisher":{"@id":"https:\/\/machinelearningplus.com\/#organization"},"image":{"@id":"https:\/\/machinelearningplus.com\/python\/requests-in-python\/#primaryimage"},"thumbnailUrl":"https:\/\/machinelearningplus.com\/wp-content\/uploads\/2020\/04\/MACHINE-LEARNING-PLUS-A-Complete-Beginners-Guide-to-SQLite-IN-Python-3.png","keywords":["HTTP","Python","Requests"],"articleSection":["Python"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/machinelearningplus.com\/python\/requests-in-python\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/machinelearningplus.com\/python\/requests-in-python\/","url":"https:\/\/machinelearningplus.com\/python\/requests-in-python\/","name":"Requests in Python Tutorial - How to send HTTP requests in Python? - machinelearningplus","isPartOf":{"@id":"https:\/\/machinelearningplus.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/machinelearningplus.com\/python\/requests-in-python\/#primaryimage"},"image":{"@id":"https:\/\/machinelearningplus.com\/python\/requests-in-python\/#primaryimage"},"thumbnailUrl":"https:\/\/machinelearningplus.com\/wp-content\/uploads\/2020\/04\/MACHINE-LEARNING-PLUS-A-Complete-Beginners-Guide-to-SQLite-IN-Python-3.png","datePublished":"2020-04-18T11:22:12+00:00","dateModified":"2022-10-10T11:16:43+00:00","description":"Learn how to send HTTP requests in Python using the Requests library. Covers GET, POST, PUT, DELETE methods, headers, parameters, and response handling.","inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/machinelearningplus.com\/python\/requests-in-python\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/machinelearningplus.com\/python\/requests-in-python\/#primaryimage","url":"https:\/\/machinelearningplus.com\/wp-content\/uploads\/2020\/04\/MACHINE-LEARNING-PLUS-A-Complete-Beginners-Guide-to-SQLite-IN-Python-3.png","contentUrl":"https:\/\/machinelearningplus.com\/wp-content\/uploads\/2020\/04\/MACHINE-LEARNING-PLUS-A-Complete-Beginners-Guide-to-SQLite-IN-Python-3.png","width":1280,"height":720},{"@type":"WebSite","@id":"https:\/\/machinelearningplus.com\/#website","url":"https:\/\/machinelearningplus.com\/","name":"machinelearningplus","description":"Learn Data Science (AI \/ ML) Online","publisher":{"@id":"https:\/\/machinelearningplus.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/machinelearningplus.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/machinelearningplus.com\/#organization","name":"machinelearningplus","url":"https:\/\/machinelearningplus.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/machinelearningplus.com\/#\/schema\/logo\/image\/","url":"https:\/\/machinelearningplus.com\/wp-content\/uploads\/2022\/05\/MachineLearningplus-logo.svg","contentUrl":"https:\/\/machinelearningplus.com\/wp-content\/uploads\/2022\/05\/MachineLearningplus-logo.svg","width":348,"height":36,"caption":"machinelearningplus"},"image":{"@id":"https:\/\/machinelearningplus.com\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/machinelearningplus.com\/#\/schema\/person\/5496cd92445387e04c3ee0737a78efa0","name":"Venmani A D","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/machinelearningplus.com\/wp-content\/litespeed\/avatar\/d1b80494908c2c820cbd96a6a804f163.jpg?ver=1776364784","url":"https:\/\/machinelearningplus.com\/wp-content\/litespeed\/avatar\/d1b80494908c2c820cbd96a6a804f163.jpg?ver=1776364784","contentUrl":"https:\/\/machinelearningplus.com\/wp-content\/litespeed\/avatar\/d1b80494908c2c820cbd96a6a804f163.jpg?ver=1776364784","caption":"Venmani A D"},"url":"https:\/\/machinelearningplus.com\/author\/venmani\/"}]}},"_links":{"self":[{"href":"https:\/\/machinelearningplus.com\/wp-json\/wp\/v2\/posts\/2690","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/machinelearningplus.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/machinelearningplus.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/machinelearningplus.com\/wp-json\/wp\/v2\/users\/7"}],"replies":[{"embeddable":true,"href":"https:\/\/machinelearningplus.com\/wp-json\/wp\/v2\/comments?post=2690"}],"version-history":[{"count":0,"href":"https:\/\/machinelearningplus.com\/wp-json\/wp\/v2\/posts\/2690\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/machinelearningplus.com\/wp-json\/wp\/v2\/media\/3490"}],"wp:attachment":[{"href":"https:\/\/machinelearningplus.com\/wp-json\/wp\/v2\/media?parent=2690"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/machinelearningplus.com\/wp-json\/wp\/v2\/categories?post=2690"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/machinelearningplus.com\/wp-json\/wp\/v2\/tags?post=2690"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}