From ab60e08e2e34ac4a87bc6c1701c6ace69bb392cf Mon Sep 17 00:00:00 2001 From: Tim Burke Date: Thu, 25 Aug 2016 10:51:29 -0700 Subject: Convert numeric and boolean header values to strings Recently, requests got a bit more picky about what types of data it will accept as header values [1]. The reasons for this are generally sound; str()ing arbitrary objects just before pushing them out a socket may not do what the developer wanted/expected. However, there are a few standard types that developers may be sending that we should convert for them as a convenience. Now, we'll convert all int, float, and bool values to strings before sending them on to requests. Change-Id: I6c2f451009cb03cb78812f54e4ed8566076de821 Closes-Bug: 1614932 --- swiftclient/client.py | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'swiftclient/client.py') diff --git a/swiftclient/client.py b/swiftclient/client.py index 602489d..7515f7c 100644 --- a/swiftclient/client.py +++ b/swiftclient/client.py @@ -211,6 +211,13 @@ def quote(value, safe='/'): def encode_utf8(value): + if type(value) in six.integer_types + (float, bool): + # As of requests 2.11.0, headers must be byte- or unicode-strings. + # Convert some known-good types as a convenience for developers. + # Note that we *don't* convert subclasses, as they may have overriddden + # __str__ or __repr__. + # See https://github.com/kennethreitz/requests/pull/3366 for more info + value = str(value) if isinstance(value, six.text_type): value = value.encode('utf8') return value -- cgit v1.2.1