{"id":6706,"date":"2020-02-24T19:03:36","date_gmt":"2020-02-24T13:33:36","guid":{"rendered":"https:\/\/codeforgeek.com\/?p=6706"},"modified":"2023-12-22T19:05:33","modified_gmt":"2023-12-22T13:35:33","slug":"get-and-post-requests-using-python","status":"publish","type":"post","link":"https:\/\/codeforgeek.com\/get-and-post-requests-using-python\/","title":{"rendered":"GET and POST requests using Python"},"content":{"rendered":"<p>Here is a quick guide to perform GET and POST requests using Python.<\/p>\n<p>We are going to use <strong>requests<\/strong> module. Install it using pip.<\/p>\n<p><code><br \/>\npip install requests<br \/>\n<\/code><\/p>\n<p>Here is the code to perform the GET request.<\/p>\n<p><code lang='python'><br \/>\nimport requests<br \/>\nurl = 'https:\/\/codeforgeek.com'<\/p>\n<p>x = requests.get(url)<br \/>\nprint(x)<br \/>\n<\/code><\/p>\n<p>If you want to send parameters, pass it along with the URL.<\/p>\n<p><code lang='python'><br \/>\nimport requests<br \/>\nurl = 'https:\/\/codeforgeek.com'<br \/>\ndata = {'id': 123}<br \/>\nx = requests.get(url,params = data)<br \/>\nprint(x)<br \/>\n<\/code><\/p>\n<p>Here is how to send the POST request.<\/p>\n<p><code lang='python'><br \/>\nimport requests<\/p>\n<p>url = 'https:\/\/codeforgeek.com'<br \/>\ndata = {'key': 'value'}<\/p>\n<p>r = requests.post(url, data = data)<\/p>\n<p>print(r.text) \/\/ or r.json<br \/>\n<\/code><\/p>\n<p>Here is the code send the file in POST request in the multipart form.<\/p>\n<p><code lang='python'><br \/>\nimport requests<\/p>\n<p>url = 'https:\/\/codeforgeek.com'<br \/>\ndata = {'key': 'value'}<br \/>\nfile = ('file': open('filepath','rb')) \/\/example \/home\/pi\/Desktop\/user.pdf<\/p>\n<p>r = requests.post(url, files = file, data = data)<\/p>\n<p>print(r.text) \/\/ or r.json<br \/>\n<\/code><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Here is a quick guide to perform GET and POST requests using Python. We are going to use requests module. Install it using pip. pip install requests Here is the code to perform the GET request. import requests url = &#8216;https:\/\/codeforgeek.com&#8217; x = requests.get(url) print(x) If you want to send parameters, pass it along with [&hellip;]<\/p>\n","protected":false},"author":69,"featured_media":6358,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_surecart_dashboard_logo_width":"180px","_surecart_dashboard_show_logo":true,"_surecart_dashboard_navigation_orders":true,"_surecart_dashboard_navigation_invoices":true,"_surecart_dashboard_navigation_subscriptions":true,"_surecart_dashboard_navigation_downloads":true,"_surecart_dashboard_navigation_billing":true,"_surecart_dashboard_navigation_account":true,"_uag_custom_page_level_css":"","footnotes":""},"categories":[134,16],"tags":[],"class_list":["post-6706","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-python","category-short-tips"],"blocksy_meta":[],"uagb_featured_image_src":{"full":["https:\/\/codeforgeek.com\/wp-content\/uploads\/hitesh-choudhary-D9Zow2REm8U-unsplash-min.jpg",2048,1152,false],"thumbnail":["https:\/\/codeforgeek.com\/wp-content\/uploads\/hitesh-choudhary-D9Zow2REm8U-unsplash-min-150x150.jpg",150,150,true],"medium":["https:\/\/codeforgeek.com\/wp-content\/uploads\/hitesh-choudhary-D9Zow2REm8U-unsplash-min-300x169.jpg",300,169,true],"medium_large":["https:\/\/codeforgeek.com\/wp-content\/uploads\/hitesh-choudhary-D9Zow2REm8U-unsplash-min-768x432.jpg",768,432,true],"large":["https:\/\/codeforgeek.com\/wp-content\/uploads\/hitesh-choudhary-D9Zow2REm8U-unsplash-min-1024x576.jpg",1024,576,true],"1536x1536":["https:\/\/codeforgeek.com\/wp-content\/uploads\/hitesh-choudhary-D9Zow2REm8U-unsplash-min.jpg",1536,864,false],"2048x2048":["https:\/\/codeforgeek.com\/wp-content\/uploads\/hitesh-choudhary-D9Zow2REm8U-unsplash-min.jpg",2048,1152,false]},"uagb_author_info":{"display_name":"Pankaj Kumar","author_link":"https:\/\/codeforgeek.com\/author\/pankaj\/"},"uagb_comment_info":0,"uagb_excerpt":"Here is a quick guide to perform GET and POST requests using Python. We are going to use requests module. Install it using pip. pip install requests Here is the code to perform the GET request. import requests url = 'https:\/\/codeforgeek.com' x = requests.get(url) print(x) If you want to send parameters, pass it along with&hellip;","_links":{"self":[{"href":"https:\/\/codeforgeek.com\/wp-json\/wp\/v2\/posts\/6706","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/codeforgeek.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/codeforgeek.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/codeforgeek.com\/wp-json\/wp\/v2\/users\/69"}],"replies":[{"embeddable":true,"href":"https:\/\/codeforgeek.com\/wp-json\/wp\/v2\/comments?post=6706"}],"version-history":[{"count":0,"href":"https:\/\/codeforgeek.com\/wp-json\/wp\/v2\/posts\/6706\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/codeforgeek.com\/wp-json\/wp\/v2\/media\/6358"}],"wp:attachment":[{"href":"https:\/\/codeforgeek.com\/wp-json\/wp\/v2\/media?parent=6706"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/codeforgeek.com\/wp-json\/wp\/v2\/categories?post=6706"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/codeforgeek.com\/wp-json\/wp\/v2\/tags?post=6706"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}