Basic authentication in python?

Third-party modifications and add-ons, Apps and Clients

Moderator: moderators

Basic authentication in python?

Postby BestMuted » Thu Nov 11, 2010 4:32 pm

I am trying to use basic authentication with python, but I am still getting an error "Required parameter is missing." I am probably doing something wrong.
I am probably mis-reading this tutorial, but I am kinda lost http://www.voidspace.org.uk/python/arti ... ion.shtmlc

Here's the code I am using

Code: Select all

def login(username, password):

    import urllib2

    superURL = 'http://localhost:8090/rest/'
    username = 'aaa'
    password = 'bbb'

    passman = urllib2.HTTPPasswordMgrWithDefaultRealm()
    passman.add_password(None, superURL, username, password)
    authhandler = urllib2.HTTPBasicAuthHandler(passman)
    opener = urllib2.build_opener(authhandler)
    urllib2.install_opener(opener)

    pagehandle = urllib2.urlopen("http://localhost:8090/rest/getIndexes.view?v=1.3.0&c=myapp")
    print parse(pagehandle).toxml()

BestMuted
 
Posts: 7
Joined: Thu Sep 09, 2010 4:17 pm

Postby tags07 » Sat Mar 19, 2011 4:29 pm

How do you use basic authentication?

pagehandle = urllib2.urlopen("http://localhost:8090/rest/getIndexes.view?v=1.3.0&c=myapp")

always comes back with:

Code: Select all
<subsonic-response xmlns="http://subsonic.org/restapi" status="failed" version="1.4.0">
  <error code="10" message="Required parameter is missing."/>
</subsonic-response>


The only way to get it working is to pass user and password in the url. How does the basic authentication stuff work with python as an example?
tags07
 
Posts: 3
Joined: Tue Mar 30, 2010 9:27 pm

Postby alexj212 » Sat Apr 16, 2011 3:21 pm

Here is how I create rest commands urls.

Code: Select all
    def createUrl(self, method, args=[]):
        url = "http://%s/rest/%s?u=%s&p=%s&v=%s&c=%s&f=json" % (self.subsonic_server, method, self.user, self.password, self.api_version, self.app_name)
        for x in args:
            if x is not None:
                url= url+"&"+x
        print url
        return url
alexj212
 
Posts: 6
Joined: Tue Feb 15, 2011 11:00 am

Postby crustymonkey » Fri Apr 22, 2011 8:11 pm

I just put a basic Python library up on github to wrap the REST API yesterday. It takes care of all of this stuff for you:

https://github.com/crustymonkey/py-sonic
crustymonkey
 
Posts: 6
Joined: Tue Nov 23, 2010 4:29 pm


Return to Mods, Apps and Clients

Who is online

Users browsing this forum: No registered users and 9 guests