[Httplib2-discuss] Feedback on httplib2
Status: Beta
Brought to you by:
jcgregorio
From: Simon W. <swi...@gm...> - 2006-07-25 12:42:19
|
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') >>> 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? 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. Thanks, Simon Willison |