Welcome to the Panopto Community

Please note: All new registrants to the Panopto Community Forum must be approved by a forum moderator or admin. As such, if you navigate to a feature that is members-only, you may receive an error page if your registration has not yet been approved. We apologize for any inconvenience and are approving new members as quickly as possible.

Python SOAP API example

New to using the SOAP API - I was working through this example, shared by Panopto support: https://github.com/Panopto/python-soap/blob/python3/examples/stats_report_example.py

I'm relying on these functions: https://github.com/Panopto/python-soap/tree/master/src/panopto_api

Has anyone gotten an issue with the response , where it's looking for a key 'Set-Cookie', which seems to not be returned (despite a 200 response). I tried reading the docs to see what the field names are that would be returned upon authentication, and I may be looking at the wrong part of the documentation: https://support.panopto.com/resource/APIDocumentation/Help/html/bfb68bf4-a7f7-f0c8-21cb-ebdaf9130caa.htm (but it's not clear to me how the response would look, there is no sample and it looks like a boolean is returned)

My code and the error are pasted below, thank you in advance for any insight. I verified the host with Panopto support.

CODE:

from panopto_api.AuthenticatedClientFactory import AuthenticatedClientFactory
from panopto_api.ClientWrapper import ClientWrapper
from datetime import datetime, timedelta
from time import sleep
from io import BytesIO
import zipfile

host = '<insert host>'
username = 'admin'
password = '<insert local password>'

# create a client factory for making authenticated API requests
auth = AuthenticatedClientFactory(
  host, username, password, verify_ssl=host != 'localhost')
# create a client for calling the usage reporting endpoint
usage = auth.get_client('UsageReporting')

ERROR:

KeyError                                  Traceback (most recent call last)
<ipython-input-5-e5bba193295d> in <module>
     17 
     18 # create a client for calling the usage reporting endpoint
---> 19 usage = auth.get_client('UsageReporting')

~/<insert path>/panopto_api/AuthenticatedClientFactory.py in get_client(self, endpoint, over_ssl, authenticate_now, as_wrapper)
     65             transport=transport)
     66         if authenticate_now:
---> 67             self.authenticate_client(client)
     68         if as_wrapper:
     69             client = ClientWrapper(client)

~/<insert path>/panopto_api/AuthenticatedClientFactory.py in authenticate_client(self, client)
     99         '''
    100         if self.cookie is None:
--> 101             if not self.authenticate_factory():
    102                 return False
    103         client.transport.session.headers.update({'Cookie': self.cookie})

~/<insert path>/panopto_api/AuthenticatedClientFactory.py in authenticate_factory(self)
     88                 password=self.password)
     89             if response.status_code == 200:
---> 90                 self.cookie = response.headers['Set-Cookie']
     91                 return True
     92 

~/anaconda3/envs/<insert env>/lib/python3.7/site-packages/requests/structures.py in __getitem__(self, key)
     52 
     53     def __getitem__(self, key):
---> 54         return self._store[key.lower()][1]
     55 
     56     def __delitem__(self, key):

KeyError: 'set-cookie'

Answers

  • Mark BrewsalaMark Brewsala Panopto Employee

    Hi Terianne,

    Thank you for reporting your trouble here. Can you please confirm which python version you wish to target? We're midway through migrating the repo from python2 to python3.

    I think you're after python3 since this example is in the python3 branch of the sample repo: /python-soap/blob/python3/examples/stats_report_example.py

    But you mention the python2 code currently in master: /Panopto/python-soap/tree/master/src/panopto_api

    I can run the python3 code in python3 locally and get past your error report. Running the python2 library from a python3 console, I also hit an error in auth.get_client('UsageReporting') -- but it wasn't identical to yours. Maybe you made some local edits?

    The other dependency that might be at play here is your version of the zeep package that actually does the SOAP heavy lifting underneath our wrapper library. Can you run pip show zeep? I'm using version 3.1.0.

    Thanks,

    Mark

  • Hi Mark,

    Thanks for the response. Versions below, I can create a new environment with a different version of Zeep if you think that's the best approach. Would you let me know about your Python version as well just in case?

    Python 3.7.6

    Zeep 4.0.0

    I updated AuthenticatedClientFactory.py and ClientWrapper.py to be from the right repository. I think I had done this but may have referred to the wrong link, either way, repasting the (maybe new) error below.

    KeyError                                  Traceback (most recent call last)
    <ipython-input-8-522a8a4e9647> in <module>
         17 
         18 # create a client for calling the usage reporting endpoint
    ---> 19 usage = auth.get_client('UsageReporting')
    
    ~/<path>/AuthenticatedClientFactory.py in get_client(self, endpoint, over_ssl, authenticate_now, as_wrapper)
         65             transport=transport)
         66         if authenticate_now:
    ---> 67             self.authenticate_client(client)
         68         if as_wrapper:
         69             client = ClientWrapper(client)
    
    ~/<path>/AuthenticatedClientFactory.py in authenticate_client(self, client)
         99         '''
        100         if self.cookie is None:
    --> 101             if not self.authenticate_factory():
        102                 return False
        103         client.transport.session.headers.update({'Cookie': self.cookie})
    
    ~/<path>/AuthenticatedClientFactory.py in authenticate_factory(self)
         88                 password=self.password)
         89             if response.status_code == 200:
    ---> 90                 self.cookie = response.headers['Set-Cookie']
         91                 return True
         92 
    
    ~/anaconda3/envs/<env>/lib/python3.7/site-packages/requests/structures.py in __getitem__(self, key)
         52 
         53     def __getitem__(self, key):
    ---> 54         return self._store[key.lower()][1]
         55 
         56     def __delitem__(self, key):
    
    KeyError: 'set-cookie'
    


  • Hi Mark,

    Small update, I created a new environment:

    Python 3.9.2

    Zeep 3.1.0

    And am getting the same error.

  • Mark BrewsalaMark Brewsala Panopto Employee

    Thanks for confirming those details. I think we've ruled out a python code bug.

    Instead, I think the problem may be that you're trying to use a unified/single-sign-on user with the API. That's currently unsupported with the SOAP API. Instead, you should use a Panopto admin user account (with a username and password) for your recurring SOAP API calls. The recommended practice is to have a user just for this purpose so you can audit its activity and suspend its access if needed.

    If that's not the case or if you're concerned with that approach, please open a support ticket so we can discuss your particular requirements.

    Sorry about the confusion here!

    -Mark

Sign In or Register to comment.