Day #89 - Requests Module in Python

Day #89 - Requests Module in Python

ยท

3 min read

Introduction

Welcome to my 89th blog post on the Python journey. On day 89, I learned about an 'HTTP' library 'REQUEST' MODULE in Python that can be used to send HTTP requests to interact with API's and web services. Let's dive into more details and understand Request module in Python.

So let's get started......

Request Module

  • It is an HTTP library that can be used to send HTTP requests in Python by the developers.

  • This module sends HTTP requests and makes it possible to interact with APIs and web services.

Install Request Module using the below syntax

pip install requests

Get Request

Once the installation is done of Request Module, we can start to send HTTP requests. Below is the example that sends GET request to Google homepage

import requests
response = requests.get("https://www.google.com")
print(response.text)

Post Request

Below is the example that sends Post request

import requests

url = "https://api.example.com/login"
headers = {
    "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36",
    "Content-Type": "application/json"
}
data = {
    "username": "myusername",
    "password": "mypassword"
}

response = requests.post(url, headers=headers, json=data)

print(response.text)

In this example, we send a POST request to a web service to authenticate a user.

bs4 Module

BeautifulSoup is a module that can be used for web scraping in Python that uses HTTP requests.

Resources Used

You can watch the video of Day#89 by clicking on the below link ๐Ÿ‘‡๐Ÿ‘‡๐Ÿ‘‡๐Ÿ‘‡๐Ÿ‘‡

Conclusion

Thanks, guys for going through this blog post. On day 89, I learned the Requests Module to send HTTP requests in Python

Thank you if you read this post and have found this post useful. I hope you have joined me and are enjoying my magical journey of Python coding. This is it for Day #89

See you in the next one.....


About Me

Hey Guys, I am Chintan Jain from CodeWithJain. I am a trader and content creator. I am also passionate about tech and hence wanted to explore the field of tech. I always wanted to learn to code so I watched many tutorials but procrastinated practicing coding. To get into the habit of coding consistently I am starting to BLOG with HASHNODE on daily basis.

I will document my coding journey from scratch and share my daily learnings in a blog post on HASHNODE. I hope you all will enjoy my content and my coding journey.

So what are you waiting for, smash the FOLLOW and LIKE buttons and follow along my coding journey, a step to create more beautiful digital products and empower people.


ย