Re: Authentication with shotrunner xml

Cameron O'Rourke's Avatar

Cameron O'Rourke

13 Apr, 2009 02:38 PM via email

On Apr 13, 2009, at 7:05 AM, Sunit Parekh-Gaihede wrote:

I've written a simple python script that creates a sequence/shot dictionary from
the shots.xml and sequence.xml files. I'm having trouble getting
authentication from the respective urls, though. This is also the
case from a browser - if I browse directly to:

http://hydralab.shotrunner.com/shots.xml

my standard user authentication doesn't work. Is this something you
can help with? For the short term, we can definitely just grab the
xml files manually, and put them on our systems.

  1. Support Staff 2 Posted by cameron on 13 Apr, 2009 02:58 PM

    cameron's Avatar

    This is task 652 awaiting estimation. Priority set to high.

  2. Support Staff 3 Posted by cameron on 21 Apr, 2009 03:10 PM

    cameron's Avatar

    We managed to fix the problem with using basic authentication on the XML API.

    Here is an example:

    $ curl -H 'Accept: application/xml' -H 'Content-Type: application/xml'
    -u sam:sam1 "http://tutorial.shotrunner.com/projects/3/sequences/1.xml"
    
    <?xml version="1.0" encoding="UTF-8"?>
    <sequence>
     <created-at type="datetime">2008-06-14T13:41:29+00:00</created-at>
     <description>Four people are lying in stasis. The camera pushes in and over.</description>
     <id type="integer">1</id>
     <lock-version type="integer">14</lock-version>
     <project-id type="integer">3</project-id>
     <sequence-code>STR</sequence-code>
     <sort-order type="integer">1</sort-order>
     <status>A</status>
     <title>Stasis Tube Room</title>
     <updated-at type="datetime">2009-04-02T12:23:16+00:00</updated-at>
    </sequence>
    

    For some reason, you can omit the headers and it still works:

    curl -u sam:sam1 "http://tutorial.shotrunner.com/projects/3/sequences/1.xml"
    

    The trick is that you must include the project number in the URL, or you will get redirected. Unfortunately, the XML for projects is not working yet. To list projects you'll have to scrape the HTML:

    curl -u sam:sam1 "http://tutorial.shotrunner.com/projects"
    

    And look for the string: 'a href="/projects/'

    Here are some examples:

    List all sequences:

    curl -u sam:sam1 "http://tutorial.shotrunner.com/projects/3/sequences.xml"
    

    List one sequence:

    curl -u sam:sam1 "http://tutorial.shotrunner.com/projects/3/sequences/1.xml"
    

    List all shots:

    curl -u sam:sam1 "http://tutorial.shotrunner.com/projects/3/shots.xml"
    

    List one shot:

    curl -u sam:sam1 "http://tutorial.shotrunner.com/projects/3/shots/2.xml"
    

    List all tasks:

    curl -u sam:sam1 "http://tutorial.shotrunner.com/projects/3/tasks.xml"
    

    List one task:

    curl -u sam:sam1 "http://tutorial.shotrunner.com/projects/3/tasks/1.xml"
    

    List tasks using "My Tasks" filter:

    curl -u sam:sam1 "http://tutorial.shotrunner.com/projects/3/tasks.xml?filter=1"
    

    Updating a field:

    curl -H 'Accept: application/xml' -H 'Content-Type: application/xml' -u sam:sam1 -X PUT -d "<?xml version ='1.0' encoding 'UTF-8'?><shot><frame-count>55</frame-count></shot>" "http://tutorial.shotrunner.com/projects/3/shots/6.xml"
    

    Here is a very simple Python script that retrieves the sequence names:

    import urllib2
    from xml.etree import ElementTree as ET
    
    # Create an OpenerDirector with support for Basic HTTP Authentication...
    auth_handler = urllib2.HTTPBasicAuthHandler()
    auth_handler.add_password(realm='Web Password',
                            uri='http://tutorial.shotrunner.com/',
                            user='sam',
                            passwd='sam1')
    opener = urllib2.build_opener(auth_handler)
    
    # ...and install it globally so it can be used with urlopen.
    urllib2.install_opener(opener)
    
    # Open the 'file' stream to the web server
    file = urllib2.urlopen('http://tutorial.shotrunner.com/projects/3/sequences.xml')
    
    # Fetch and parse the XML (parse invokes the read method on the object)
    tree = ET.parse(file)
    
    # Get the root Element of the XML (it should be 'sequences')
    root = tree.getroot()
    
    # Get each subelement (each should be an Element of type 'sequence')
    for seqnode in root:
        print "ID: " + seqnode.find('id').text + "\tTitle: " + seqnode.find('title').text
    
  3. cameron resolved this discussion on 21 Apr, 2009 03:10 PM.

Comments are currently closed for this discussion. You can start a new one.