Query re editing script for 2FA

26 views
Skip to first unread message

Laura Peaurt

unread,
Jul 12, 2023, 5:54:18 AM7/12/23
to pyPreservica
Hi there,

Apologies that I have tried to understand this but really can't get it...

I use a script to report on contents of specific folders - particularly to get reports on formats and size.

The script taken from James' previously supplied examples (and edited a bit) has worked until recently when I get an error message relating to 2FA.

I presume I need to change the way I input store my password information, but I'm afraid I have no idea how to put this into the code / files.
Just to note we have used 2FA within Preservica for some time now.

Any advice / help appreciated!

Many thanks

Laura

Script used as below from James examples (I have taken out my account details throughout):

from pyPreservica import *

content = ContentAPI()
entity = EntityAPI()

folder = entity.folder("f78fc2a3-6e66-48f9-9527-fa2131806ade")

print(f"Searching inside folder {folder.title}")

if __name__ == '__main__':
    metadata_fields = {
        "xip.reference": "*", "xip.title": "", "xip.description": "", "xip.document_type": "*", "xip.parent_hierarchy": f"{folder.reference}",
        "xip.security_descriptor": "*",
        "xip.identifier": "", "xip.bitstream_names_r_Preservation": "", "xip.format_r_Preservation": "", "xip.size_r_Preservation": ""}


    content.search_callback(content.ReportProgressCallBack())

    content.search_index_filter_csv("%", "assetsinfo.csv", metadata_fields)

.................................................................................................
And then credentials file stored in same folder:

[credentials]
username=[myusername]        
password=[mypassword]
tenant=[ourtenant]
server=[europeserver]

...............................................................................................

Returns following error:

Failed to create a password based authentication token. Check your credentials are correct
b'{"success":false,"message":"needs.2fa","user":"[myusername]","tenant":"[ourtenant]","continuationToken":"57a4ae34-d62f-4a8b-9e36-8ea61a9cd156"}'
Traceback (most recent call last):
  File "C:\Users\uazlp\Desktop\API.Workshop\formatandsizereport.py", line 3, in <module>
    content = ContentAPI()
  File "C:\Users\uazlp\AppData\Local\Programs\Python\Python310\lib\site-packages\pyPreservica\contentAPI.py", line 22, in __init__
    super().__init__(username, password, tenant, server, use_shared_secret)
  File "C:\Users\uazlp\AppData\Local\Programs\Python\Python310\lib\site-packages\pyPreservica\common.py", line 838, in __init__
    self.token = self.__token__()
  File "C:\Users\uazlp\AppData\Local\Programs\Python\Python310\lib\site-packages\pyPreservica\common.py", line 759, in __token__
    raise RuntimeError(response.status_code, msg)
RuntimeError: (401, 'Failed to create a password based authentication token. Check your credentials are correct')

James Carr

unread,
Jul 12, 2023, 7:10:54 AM7/12/23
to pyPreservica
Hi

Yes, the way the Preservica API works with systems setup with two factor authentication has recently changed.  

You will need to add a second password to your credentials.properties file, you can find this new password when you turn on two factor authentication for a user.

The process is described here.  You may need to disable 2-FA for the account and then re-enabled it.

https://pypreservica.readthedocs.io/en/latest/intro.html#factor-authentication

Laura Peaurt

unread,
Aug 9, 2023, 10:58:40 AM8/9/23
to pyPreservica
Hi James,

Just to belatedly update and say thank you - with this change (and updating my pyPreservica version) this is now working again :-)

Kind regards,

Laura

Reply all
Reply to author
Forward
0 new messages