Skip to main content

http1 is an API to perform HTTP requests in a single call

Project description

HTTP1 is a wrapper around httplib to perform HTTP requests in a single call. For instance, to get PyPI index of packages, you might write:

import http1

print http1.request('http://pypi.python.org/simple/').body

request() method

This method performs an HTTP request. The signature of the request method is the following:

request(url, params={}, method='GET', body=None, headers={},
        content_type=None, content_length=True, username=None,
        password=None, capitalize_headers=True,
        follow_redirect=True, max_redirect=3)

The parameters are the following:

  • url: the URL call, including protocol and parameters (such as ‘http://www.google.com?foo=1&bar=2’).

  • params: URL parameters as a map, so that {‘foo’: 1, ‘bar’: 2} will result in an URL ending with ‘?foo=1&bar=2’.

  • method: the HTTP method (such as ‘GET’ or ‘POST’). Defaults to ‘GET’.

  • body: the body of the request as a string. Defaults to None.

  • headers: request headers as a dictionnary. Defaults to ‘{}’.

  • content_type: the content type header of the request. Defauls to None.

  • content_length: tells if we should add content length headers to the request. Defaults to true.

  • username: username while performing basic authentication, must be set with password.

  • password: password while performing basic authentication, must be set with username.

  • capitalize_headers: tells if headers should be capitalized (so that their names are all like ‘Content-Type’ for instance).

  • follow_redirect: tells if http1 should follow redirections (status codes 3xx). Defaults to True.

  • max_redirect: maximum number of redirections to follow. If there are too many redirects, a TooManyRedirectsException is raised. Defaults to 3.

This method returns the response as a Response object described hereafter.

May raise a TooManyRedirectsException.

NOTE: to call HTTPS URLs, Python must have been built with SSL support.

There are dedicated functions for HTTP methods (GET, HEAD, POST, PUT, DELETE, CONNECT, OPTIONS and TRACE). Thus, to perform a head call for instance, you may write:

response = http1.head('http://www.example.com')

Which is the same as:

response = http1.request('http://www.example.com', method='HEAD')

Response object

This object encapsulates status code (200, 404, as an integer), message (such as ‘OK’, ‘Not Found’, as a string), headers (as a dictionnary), and body (as a string).

TooManyRedirectsException

This exception is thrown when there have been too many redirects (that is a number of refirects greater than max_redirect).

Enjoy!

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

http1-0.4.0.tar.gz (7.7 kB view details)

Uploaded Source

File details

Details for the file http1-0.4.0.tar.gz.

File metadata

  • Download URL: http1-0.4.0.tar.gz
  • Upload date:
  • Size: 7.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for http1-0.4.0.tar.gz
Algorithm Hash digest
SHA256 8492419aa9e642fdbfe9f32d0af1e1ed8bb9486ac03c29a007981ba6eaaa1107
MD5 c2462b2401e3c2a59d8fc9de93aefed2
BLAKE2b-256 28c2f808f22bcfe72a35373bd817e324fd9b0f6649b1dcf43be3217dacfb8838

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page