[openstack-dev] [glance] content-type always set to application/octet-stream

Carlos Konstanski ckonstanski at pippiandcarlos.com
Fri Nov 11 18:20:21 UTC 2016


On Fri, 11 Nov 2016, Carlos Konstanski wrote:

> Date: Fri, 11 Nov 2016 10:17:09 -0700 (MST)
> From: Carlos Konstanski <ckonstanski at pippiandcarlos.com>
> Reply-To: "OpenStack Development Mailing List (not for usage questions)"
>     <openstack-dev at lists.openstack.org>
> To: openstack-dev at lists.openstack.org
> Subject: [openstack-dev] [glance] content-type always set to
>     application/octet-stream
> 
> glance --version : 2.5.0
> File: common/http.py
> Class: _BaseHTTPClient
> Method: _set_common_request_kwargs
> Python version: 3.4
>
> First problem
> -------------
>
> There is a line of code in this method that fetches the Content-Type
> header from the passed-in headers dict:
>
> content_type = headers.get('content-type', 'application/octet-stream')
>
> However it fails because the headers dict has strings that are not
> represented as unicode:
>
> (Pdb) print(headers)
> {b'Content-Type': b'application/openstack-images-v2.1-json-patch'}
>
> Therefore the lookup fails:
>
> (Pdb) print(headers.get("Content-Type"))
> None
>
> But if we use a key that is coerced to the right type, it works:
>
> (Pdb) print(headers.get(b"Content-Type"))
> b'application/openstack-images-v2.1-json-patch'
>
> The question I have yet to answer is: are these strings supposed to be
> char sequences, or did they get converted by mistake due to a different
> bug? That's really the first thing to figure out.
>
> Second problem
> --------------
>
> The headers.get() call gets the case wrong. It should be Content-Type,
> but instead it uses content-type.
>
> Path to fix
> -----------
>
> I would be happy to fix this. This would be my first upstream
> contribution, and I know there is a process to even get to square
> one. Should I start down that path, or does someone else wish to address
> this bug?
>
> Sincerely,
> Carlos Konstanski

Found the issue: oslo_utils/encodeutils.py:66, method safe_encode()

It does this: return text.encode(encoding, errors)

encoding == "utf-8". This results in an object of type bytes, not str.

So glance should be fixed to work with bytes.

Carlos



More information about the OpenStack-dev mailing list