djc / couchdb-python

Python library for working with CouchDB

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

More user friendly for HTTP Basic Auth

zachcheung opened this issue · comments

In [1]: from couchdb.http import extract_credentials

In [2]: from urllib.parse import urlsplit

In [3]: url = 'http://joe:secret_has_#_@localhost:5984/_config/'

In [4]: extract_credentials(url)
Out[4]: ('http://joe:secret_has_#_@localhost:5984/_config/', None)

In [5]: urlsplit(url)
Out[5]: SplitResult(scheme='http', netloc='joe:secret_has_', path='', query='', fragment='_@localhost:5984/_config/')

Error happened when I used couchdb-python with random generated password which has number sign #. I realized that I should quote password firstly, but I thought it's not very user-friendly, quote password manually and unquoted by couchdb-python, why not just add user, password parameters or auth like Requests?

To avoid modify related codes, I implement as blow but still think not a proper way to handle it:

>>> extract_credentials('http://joe@example.com:secret_has_special_chars_@#!:_@localhost:5984/_config/')
('http://localhost:5984/_config/', ('joe@example.com', 'secret_has_special_chars_@#!:_'))

Any suggestion?

So what would you propose exactly? I think the current way is pretty pragmatic, and fits in with the design of CouchDB-Python being a fairly light-weight wrapper over het HTTP API.

@djc You're right. I think add auth parameter like requests is more user-friendly, but I'm afraid it'll break current case, so please just ignore this issue.