Python Requests – HTTP GET

Python – Send HTTP GET Request

HTTP GET request is used to request data from a specified resource. Using Python Requests library, you can make a HTTP GET request.

In this tutorial, we shall learn how to send a HTTP GET request for a URL. Also, we shall learn about the response and its components.

Examples

1. Send GET Request

In this example, we shall use requests library and send a GET request with a URL.

Python Program

import requests

response = requests.get('https://pythonexamples.org/python-basic-examples/')
Run Code

requests.get() function returns a Response object that contains parameters like html content, cookies, headers, etc.

Let us print the headers that we received in the response to the GET request made in the above example.

Python Program

import requests

response = requests.get('https://pythonexamples.org/python-basic-examples/')

print(response.headers)
Run Code

Output

{'Date': 'Mon, 25 Mar 2019 06:46:46 GMT', 'Content-Type': 'text/html; charset=UTF-8', 'Content-Length': '8053', 'Connection': 'keep-alive', 'Keep-Alive': 'timeout=30', 'Server': 'Apache/2', 'X-Powered-By': 'PHP/5.6.30', 'Link': '<https://pythonexamples.org/wp-json/>; rel="https://api.w.org/", <https://pythonexamples.org/?p=317>; rel=shortlink', 'Last-Modified': 'Mon, 25 Mar 2019 06:46:46 GMT', 'ETag': '"d8b82075ab21a19ac91f6ff4579b3722"', 'Content-Encoding': 'gzip', 'Vary': 'Accept-Encoding', 'Referrer-Policy': 'no-referrer-when-downgrade'}

Information about HTTP GET Request

Following are some of the points that can be noted while working with HTTP GET Requests.

Summary

In this tutorial of Python Examples, we learned how to send HTTP GET request and receive a response using Python requests library.

Related Tutorials

Privacy Policy Terms of Use

SitemapContact Us