Re: [Httplib2-discuss] Feedback on httplib2
Status: Beta
Brought to you by:
jcgregorio
From: Joe G. <joe...@gm...> - 2006-07-27 17:16:10
|
Simon, Sorry for the slow response, I was out getting educated on what it means to be an IBMer :) More comments inline: On 7/25/06, Simon Willison <swi...@gm...> wrote: > I've been playing with httplib2 and so far I like it - it sucks an > awful lot less than the stuff in the standard library. That said, > here are a few observations. > > 1. If you give it a URL to a site that is down / doesn't exist you > get a low level socket error. It would be nice if this was a > documented httplib2 exception. > > >>> import httplib2 > >>> httplib2.Http().request('http://non-existant-domain-oeu.com') > Traceback (most recent call last): > File "<stdin>", line 1, in ? > File "httplib2/__init__.py", line 781, in request > (response, content) = self._request(conn, authority, uri, > request_uri, method, body, headers, redirections, cachekey) > File "httplib2/__init__.py", line 603, in _request > (response, content) = self._conn_request(conn, request_uri, > method, body, headers) > File "httplib2/__init__.py", line 581, in _conn_request > conn.connect() > File "/System/Library/Frameworks/Python.framework/Versions/2.3/lib/ > python2.3/httplib.py", line 535, in connect > socket.SOCK_STREAM): > socket.gaierror: (7, 'No address associated with nodename') > >>> Yup, that's a bug. Now logged. > 2. I'm a little uncomfortable with the way authentication works - it > seems like it would be very easy to add some credentials and then > forget to clear them, potentially passing them to other sites as you > reuse the Http() instance. I would prefer something like this: > > http = Http() > http.add_credentials('https://del.icio.us/', 'username', 'password') > > That way the class knows to only send that username and password to > URLs that start with https://del.icio.us/. Is there a reason this > isn't done at the moment? For the most part I thought that you would only be connecting to one server, but I agree, this does have the possibility of leaking names and passwords to other servers unintentionally. I like the solution you suggested but would put the domain name as a last, and optional, parameter. Logged as a feature request. > > 3. Finally, I ran in to a gotcha when doing a POST request: the > service I was talking to required me to include a Content-Type: > application/x-www-form-urlencoded header. It would be nice if one of > the examples in the documentation showed this - it would have saved > me quite a bit of debugging. > > On that last note, has any consideration been given to adding a > convenience method for the common case where you wish to POST a > dictionary of name/value pairs? Something like the following: > > http = Http() > http.post_form(url, {'name': 'value'}) > > The post_form method would run urllib.urlencode on the argument > dictionary and automatically add the application/x-www-form-urlencode > header. Good idea, at the very least the docs need to be updated, I will need to poke around at what url encoding functions already exist before deciding what to add to httplib2. Logged as an enchancement request. Thanks, -joe -- Joe Gregorio http://bitworking.org |