{"id":936,"date":"2024-02-23T13:59:55","date_gmt":"2024-02-23T13:59:55","guid":{"rendered":"https:\/\/learnpython.elegantwallp.com\/?p=936"},"modified":"2024-02-23T13:59:59","modified_gmt":"2024-02-23T13:59:59","slug":"get-method-python-requests","status":"publish","type":"post","link":"https:\/\/learnpython.elegantwallp.com\/2024\/02\/23\/get-method-python-requests\/","title":{"rendered":"GET method \u2013 Python requests"},"content":{"rendered":"\n<p>Requests library is one of the important aspects of Python for making HTTP requests to a specified URL. This article revolves around how one can make GET request to a specified URL using&nbsp;<strong>requests.GET()<\/strong>&nbsp;method. Before checking out GET method, let\u2019s figure out what a GET request is \u2013<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">GET Http Method<\/h4>\n\n\n\n<p>The GET method is used to retrieve information from the given server using a given URL. The GET method sends the encoded user information appended to the page request. The page and the encoded information are separated by the \u2018?\u2019 character. For example:https:\/\/www.google.com\/search?q=hello<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">How to make GET request through Python Requests<\/h4>\n\n\n\n<p>Python\u2019s requests module provides in-built method called&nbsp;<strong>get()<\/strong>&nbsp;for making a GET request to a specified URL.&nbsp;<\/p>\n\n\n\n<p><strong>Syntax \u2013&nbsp;<\/strong>requests.get(url, params={key: value}, args)<\/p>\n\n\n\n<p><strong>Example \u2013&nbsp;<\/strong>Let\u2019s try making a request to Github\u2019s APIs for example purposes.&nbsp;<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Python3<\/li>\n<\/ul>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td><code>import<\/code><code>requests<\/code><code>&nbsp;<\/code><code># Making a GET request<\/code><code>r <\/code><code>=<\/code><code>requests.get(<\/code><code>'<a href=\"https:\/\/api.github.com\/\">https:\/\/api.github.com<\/a> \/ users \/ naveenkrnl'<\/code><code>)<\/code><code># check status code for response received<\/code><code># success code - 200<\/code><code>print<\/code><code>(r)<\/code><code># print content of request<\/code><code>print<\/code><code>(r.content)<\/code><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>save this file as request.py and through terminal run,python request.py<\/p>\n\n\n\n<p><strong>Output \u2013<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/media.geeksforgeeks.org\/wp-content\/uploads\/20200220005746\/python-requests-get-method.png\" alt=\"python-requests-get-method\"\/><\/figure>\n\n\n\n<h4 class=\"wp-block-heading\">Advantages of Using the GET Method<\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Since the data sent by the GET method are displayed in the URL, it is possible to bookmark the page with specific query string values.<\/li>\n\n\n\n<li>GET requests can be cached and GET requests remain in the browser history.<\/li>\n\n\n\n<li>GET requests can be bookmarked.<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\">Disadvantages of Using the GET Method<\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li>The GET method is not suitable for passing sensitive information such as the username and password, because these are fully visible in the URL query string as well as potentially stored in the client browser\u2019s memory as a visited page.<\/li>\n\n\n\n<li>Because the GET method assigns data to a server environment variable, the length of the URL is limited. So, there is a limitation for the total data to be sent.<\/li>\n<\/ul>\n\n\n\n<p>Don&#8217;t miss your chance to ride the wave of the data revolution! Every industry is scaling new heights by tapping into the power of data. Sharpen your skills and become a part of the hottest trend in the 21st century.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Requests library is one of the important aspects of Python for making HTTP requests to a specified URL. This article revolves around how one can make GET request to a specified URL using&nbsp;requests.GET()&nbsp;method. Before checking out GET method, let\u2019s figure out what a GET request is \u2013 GET Http Method The GET method is used [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[95],"tags":[],"class_list":["post-936","post","type-post","status-publish","format-standard","hentry","category-requests"],"_links":{"self":[{"href":"https:\/\/learnpython.elegantwallp.com\/wp-json\/wp\/v2\/posts\/936","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/learnpython.elegantwallp.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/learnpython.elegantwallp.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/learnpython.elegantwallp.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/learnpython.elegantwallp.com\/wp-json\/wp\/v2\/comments?post=936"}],"version-history":[{"count":1,"href":"https:\/\/learnpython.elegantwallp.com\/wp-json\/wp\/v2\/posts\/936\/revisions"}],"predecessor-version":[{"id":937,"href":"https:\/\/learnpython.elegantwallp.com\/wp-json\/wp\/v2\/posts\/936\/revisions\/937"}],"wp:attachment":[{"href":"https:\/\/learnpython.elegantwallp.com\/wp-json\/wp\/v2\/media?parent=936"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/learnpython.elegantwallp.com\/wp-json\/wp\/v2\/categories?post=936"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/learnpython.elegantwallp.com\/wp-json\/wp\/v2\/tags?post=936"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}