Delicious API and urllib2

Brent Bloxam brentb at beanfield.com
Mon Apr 6 20:44:52 CEST 2009


Bill wrote:
> The delicious api requires http authorization (actually https). A
> generic delicious api post url is "https://
> username:password at api.api.del.icio.us/v1/posts/add?url=http://
> example.com/&description=interesting&tags=whatever".
>
> This works fine when entered in the Firefox address bar. However
> urllib2.urlopen(delicious_post_url) chokes and returns
> "httplib.InvalidURL: nonnumeric port: 'password at api.del.icio.us".
>
> Delicious really wants that authorization stuff embedded in the url as
> it also rejected my attempts at using urllib2.HTTPBasicAuthHandler(),
> etc.
> Anybody have any hints?
> --
> http://mail.python.org/mailman/listinfo/python-list
>   
What failure were you experiencing when you were using the 
HTTPBasicAuthHandler?

Did you follow the sample code from the docs?

> import urllib2
> # Create an OpenerDirector with support for Basic HTTP Authentication...
> auth_handler = urllib2.HTTPBasicAuthHandler()
> auth_handler.add_password(realm='PDQ Application',
>                           uri='https://mahler:8092/site-updates.py',
>                           user='klem',
>                           passwd='kadidd!ehopper')
> opener = urllib2.build_opener(auth_handler)
> # ...and install it globally so it can be used with urlopen.
> urllib2.install_opener(opener)
> urllib2.urlopen('http://www.example.com/login.html'




More information about the Python-list mailing list