ducksboard / libsaas

Python library to take the pain out of using SaaS APIs. It's like an ORM for SaaS!
http://ducksboard.github.io/libsaas/
MIT License
383 stars 81 forks source link

Ducksboard password should be optional #71

Closed DZPM closed 10 years ago

DZPM commented 10 years ago

With the current version, when I want to create a Ducksboard instance, the password is mandatory.

This first snippet will fail, because the password is not provided (None):

from libsaas.services.ducksboard import Ducksboard
Ducksboard(API_KEY).user().get()

It raises an AttributeError when trying to decode the password (None), traceback:

/home/david/w/i/libsaas/libsaas/filters/auth.pyc in __call__(self, request)
     26         # in latin-1.
     27         auth = port.to_u('{0}:{1}').format(port.to_u(self.username),
---> 28                                            port.to_u(self.password))
     29         encoded = port.to_u(base64.b64encode(port.to_b(auth)), 'latin-1')
     30         header = 'Basic {0}'.format(encoded)

/home/david/w/i/libsaas/libsaas/port.pyc in to_u(val, encoding)
     49         return text_type(val)
     50 
---> 51     return val.decode(encoding)
     52 
     53 

AttributeError: 'NoneType' object has no attribute 'decode'

This second snippet does work, the only difference is that it provides an empty str ('') as the password:

from libsaas.services.ducksboard import Ducksboard
Ducksboard(API_KEY, '').user().get()

From reading the documentation I understand that the password parameter should be optional parameter, and the first snippet should work.

Note that my change only fixes this behaviour for the Ducksboard service. Maybe more services with optional password are affected by this bug, in that case maybe you should patch the BasicAuth filter.

wulczer commented 10 years ago

No, you're right, a default that causes errors when used is not a great default.

I merged your change, thanks!