django-utils v0.3.0 documentation

This Page

HTTP Helpers

A couple of utility functions for working with HTTP requests and responses.


requires httplib2

djutils.utils.http.fetch_url(url, parameters=None, http_method="GET", follow_redirects=True, timeout=4, user_agent='python-httplib2')

Fetch the data at the given URL, with optional parameters.

  • url – the URL to fetch
  • parameters – a dictionary of parameters to include in request
  • http_method – the type of HTTP request to make, default is GET
  • follow_redirects – whether to follow 30x redirects
  • timeout – set the socket timeout, which if reached will throw a socketerror
  • user_agent – user agent string to send in headers

Serialize the context_dictionary as JSON and return a HttpResponse. If the DEBUG setting is True, the mime_type is ‘text/javascript’, otherwise ‘application/json’ will be used.