What's New in WebOb 1.7


  • WebOb is no longer supported on Python 2.6 and PyPy3. PyPy3 support will be re-introduced as soon as it supports a Python version higher than 3.2 and pip fully supports the platform again.

    If you would like Python 2.6 support, please pin to WebOb 1.6, which still has Python 2.6 support.

Backwards Incompatibility

  • Response.content_type removes all existing Content-Type parameters, and if the new Content-Type is "texty" it adds a new charset (unless already provided) using the default_charset, to emulate the old behaviour you may use the following:

    res = Response(content_type='text/html', charset='UTF-8')
    assert res.content_type == 'text/html'
    assert res.charset == 'UTF-8'
    params = res.content_type_params
    # Change the Content-Type
    res.content_type = 'application/unknown'
    assert res.content_type == 'application/unknown'
    assert res.charset == None
    # This will add the ``charset=UTF-8`` parameter to the Content-Type
    res.content_type_params = params
    assert res.headers['Content-Type'] == 'application/unknown; charset=UTF-8'

    See https://github.com/Pylons/webob/pull/301 for more information.

  • Response no longer treats application/json as a special case that may also be treated as text. This means the following may no longer be used:

    res = Response(json.dumps({}), content_type='application/json')

    Since application/json does not have a charset, this will now raise an error.

    Replacements are:

    res = Response(json_body={})

    This will create a new Response that automatically sets up the the Content-Type and converts the dictionary to a JSON object internally.

    If you want WebOb to the encoding but do the conversion to JSON yourself, the following would also work:

    res = Response(text=json.dumps({}), content_type='application/json')

    This uses default_body_encoding to encode the text.

  • Response.set_cookie no longer accepts a key argument. This was deprecated in WebOb 1.5 and as mentioned in the deprecation, is being removed in 1.7


    res = Response()
    res.set_cookie(name='cookie_name', value='val')
    # or
    res.set_cookie('cookie_name', 'val')

    Instead of:

    res = Response()
    res.set_cookie(key='cookie_name', value='val')
  • Response.__init__ will no longer set the default Content-Type, nor Content-Length on Responses that don't have a body. This allows WebOb to return proper responses for things like Response(status='204 No Content').

  • Response.text will no longer raise if the Content-Type does not have a charset, it will fall back to using the new default_body_encoding. To get the old behaviour back please sub-class Response and set default_body_encoding to None. See https://github.com/Pylons/webob/pull/287

    An example of a Response class that has the old behaviour:

    class MyResponse(Response):
       default_body_encoding = None
    res = MyResponse(content_type='application/json')
    # This will raise as application/json doesn't have a charset
    res.text = 'sometext'
  • WebOb no longer supports Chunked Encoding, this means that if you are using WebOb and need Chunked Encoding you will be required to have a proxy that unchunks the request for you. Please read https://github.com/Pylons/webob/issues/279 for more background.