Python Requests Library

What is Requests?

Requests is an elegant and simple Apache2 licensed  HTTP library for Python. It is designed to be used by humans to interact with the language. This means you don’t have to manually add query strings to URLs, or form-encode your POST data.

Requests will allow you to send HTTP/1.1 requests using Python. With it, you can add content like headers, form data, multipart files, and parameters via simple Python libraries. It also allows you to access the response data of Python in the same way.

 

Installation:

 

Here, I am installing using pip. For more options, visit.

 

Let’s get started.

First lets import requests

Here, i am using a webpage within my server which open to a page like this.

 

Let’s create a Response Object r

Let’s check the current status of the site

 

Let’s get the content of the site

 

To know what encoding it uses,

Let’s change that to say,

 

You might want to do this in any situation where you can apply special logic to work out what the encoding of the content will be. For example, HTTP and XML have the ability to specify their encoding in their body. In situations like this, you should use r.content to find the encoding, and then set r.encoding. This will let you use r.text with the correct encoding.

Requests will also use custom encoding in the event. If you have created your own encoding and registered it with the codecs module, you can simply use the codec name as the value of r.encoding and Requests will handle the decoding for you.

 

There’s also a builtin JSON decoder, in case you’re dealing with JSON data:

 

With every request you send to a HTTP server, the server will send you some additional data. You can get extract data from an HTTP response using:

 

Benefits of Requests.

This is the list of features from the requests site:

  • International Domains and URLs
  • Keep-Alive & Connection Pooling
  • Sessions with Cookie Persistence
  • Browser-style SSL Verification
  • Basic/Digest Authentication
  • Elegant Key/Value Cookies
  • Automatic Decompression
  • Unicode Response Bodies
  • Multipart File Uploads
  • Connection Timeouts
  • .netrc support
  • List item
  • Python 2.6—3.4
  • Thread-safe.

An awesome lotta features!Right?

 

 

 

To know more,

http://docs.python-requests.org/en/master/

http://docs.python-requests.org/en/latest/api/

http://pypi.python.org/pypi/requests

http://docs.python-requests.org/en/latest/user/quickstart/

http://isbullsh.it/2012/06/Rest-api-in-python/#requests

http://docs.python-requests.org/en/master/user/quickstart/

 

Leave a Reply

bodrum escort - eskişehir esc - mersin escort - mersin escort bayan - mersin esc