Skip to content
This repository has been archived by the owner on Aug 20, 2022. It is now read-only.

storage_object.send() doesn't check for None in name attribute #35

Open
gjednaszewski opened this issue Feb 18, 2015 · 0 comments
Open

Comments

@gjednaszewski
Copy link

Often we use a SpooledTemporaryFile to write data to SL object storage. Previously we were using Python 2.7.2 and this worked fine. After updating to Python 2.7.9 we were running into an issue with this scenario where we would get an exception:

TypeError: expected string or buffer
File "python2.7/site-packages/object_storage/storage_object.py", line 349, in send
File "python2.7/mimetypes.py", line 291, in guess_type
File "python2.7/mimetypes.py", line 114, in guess_type
File "python2.7/urllib.py", line 1080, in splittype

It turns out in Python 2.7.4 a name attribute was added to SpooledTemporaryFile which has a value of None. (See http://bugs.python.org/issue10355) That breaks this code in send():

    if not content_type:
        _type = None
        if hasattr(data, 'name'):
            _type = mimetypes.guess_type(data.name)[0]
        content_type = (_type or
                        mimetypes.guess_type(self.name)[0] or
                        'application/octet-stream')

The issue can be fixed by changing the hasattr line:

    if not content_type:
        _type = None
        if hasattr(data, 'name') and data.name:
            _type = mimetypes.guess_type(data.name)[0]
        content_type = (_type or
                        mimetypes.guess_type(self.name)[0] or
                        'application/octet-stream')
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant