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.

Unable to download the caption file with access token

Xun ZhouXun Zhou Tyro
edited January 2023 in API

To whom it may concern,

I'm trying to use the caption download url to download the caption into txt file using Python. However, some of the url needs authorization, and so I can't simply use request library to download the caption.

Therefore, I have tried two methods, one is to use the request_session which I successfully use to call the API, but the data is empty.

All urls in the following code are from the captionDownloadUrl which I get from a folder API (https://{0}/Panopto/api/v1/folders/{1}/sessions)

requests_session = requests.Session()
requests_session.verify = False

oauth2 = PanoptoOAuth2(server, client_id, client_secret, False)
authorization(requests_session, oauth2)

resp = requests_session.get(url = url)
if inspect_response_is_unauthorized(resp):
    # Re-authorization
    authorization(requests_session, oauth2)
    # data = resp.json()
    data = resp.text # 
else:
    data = resp.text

Another is I simply add the access token to the header of the request object, like this:

import urllib.request


local_file = 'sph_caption_test.txt'


opener = urllib.request.build_opener()
opener.addheaders = [('Authorization', 'Bearer ' + access_token)]
urllib.request.install_opener(opener)
urllib.request.urlretrieve(url, local_file)

but still it doesn't work.

Therefore, I'm wondering how can I download the caption using the download url that requires authorization.


Thank you so much,

Xun

Tagged:

Answers

  • Hi Xun,

    The Panopto caption download url only works with cookie based authentication.

    You can use the legacy login api to get a cookie authentication from an oauth2 token (https://demo.hosted.panopto.com/Panopto/api/docs/index.html#/Auth/Auth_LegacyLogin).

    I hope this helps. Please let me know if you have any other questions.

    Thanks,

    Asher Finkel

  • Xun ZhouXun Zhou Tyro
    edited January 2023

    Hi Asher,

    I just tried the Auth API like this

    auth_url = 'https://{0}/Panopto/api/v1/auth/legacyLogin'.format(server)
    r = requests.get(auth_url, headers={"Authorization": 'Bearer ' + access_tokenn})
    print(r.text)
    

    According to the doc, I should get a cookie string, but it didn't return me anything. I have also tried the API in postman, and the response body is empy.

    And there is no issue when using this request to call other APIs at the same time.

    Thanks,

    Xun

  • Hi Xun,

    What is the HTTP response status code for the result of the request you are making?

    Thanks,

    Asher

  • Hi Asher,

    I've already worked it out! That issue may be just because the access_token has expired, and I solved it simply by rerunning the code.

    Thank you so much for your help!

    Xun

Sign In or Register to comment.