VanDyke Software Forums

VanDyke Software Forums (https://forums.vandyke.com/index.php)
-   Scripting (https://forums.vandyke.com/forumdisplay.php?f=14)
-   -   Error when running "Import Arbitrary Data From File to SecureCRT Sessions" script (https://forums.vandyke.com/showthread.php?t=14473)

JerelH 03-24-2021 02:58 PM

Error when running "Import Arbitrary Data From File to SecureCRT Sessions" script
 
I have recently upgraded to SecureCRT Version 9.0.1 (build 2451)
I am running it on macOS Catalina: 10.15.7 (19H524)
and when trying to run the:
"Import Arbitrary Data From File to SecureCRT Sessions"
script from the Script Examples post; I get the following error:
Code:

SyntaxError

Error: invalid syntax
File: /Volumes/GoogleDrive/My Drive/SecureCRT_Scripts/ImportArbitraryDataFromFileToSecureCRTSessions.py
Line: 443

    except Exception, objErr:

The corresponding portion of the script reads (line 443 is marked):
Code:

def OpenPathInDefaultApp(strFile):
    strPlatform = sys.platform
    crt.Session.SetStatusText("Platform: {0}".format(strPlatform))
    crt.Sleep(200)
    try:
        if sys.platform.startswith('darwin'):
            subprocess.call(('open', strFile))
        elif strPlatform == "win32":
            os.startfile(strFile)
        elif sys.platform.startswith('linux'):
            subprocess.call(('xdg-open', strFile))
        else:
            MsgBox("Unknown operating system:  " + os.name)
##Line 443->>##    except Exception, objErr:
        MsgBox(
            "Failed to open " + strFile + " with the default app.\n\n"  +
            str(objErr).replace('\\\\', '\\').replace('u\'', '\''))

I am not much of a python coder and could use some help resolving this error

jdev 03-24-2021 09:13 PM

That example script is written for Python 2.7 which is no longer supported in SecureCRT 9.0 and newer versions on the macOS platform.

Changing that line from...
except Exception, objErr:
...to:
except Exception as objErr:
... would certainly help.


Another change you'll likely need to make is on the line near line #461, so that instead of a <> on that line...
if g_strErrors <> "":
...you should have a != instead:
if g_strErrors != "":
There may very well be other changes needed to the script example you're trying to use in order for it to work with Python 3. When cycles become available for us to provide a python 3 version of the script, we'll update that post.

--Jake

JerelH 03-24-2021 09:57 PM

Thanks for pointing me in the right direction.

After a little searching I found the 2to3 tool included in Python and ran it against the script.

It went through and updated the syntax to work with Python3. Afterwards I was able to successfully import the sessions to SecureCRT 9.0.1

I'd be happy to send you the updated script if you want.

jdev 03-25-2021 02:16 PM

Quote:

Originally Posted by JerelH (Post 54816)
I found the 2to3 tool included in Python and ran it against the script.

It went through and updated the syntax to work with Python3. Afterwards I was able to successfully import the sessions to SecureCRT 9.0.1

I'm glad to hear you have a working solution for importing your CSV data into saved SecureCRT sessions in 9.0 using python 3.


Quote:

Originally Posted by JerelH (Post 54816)
I'd be happy to send you the updated script if you want.

Sure, send it!

Either attach the file to a post in this forum thread, or send it to support@vandyke.com referencing forum thread #14473 in the subject of your email message.

--Jake

JerelH 03-25-2021 03:33 PM

1 Attachment(s)
I have attached a copy of the updated file.

I had to append the extension ".txt" to allow it to be attached to my post.

I hopes this helps others.


All times are GMT -6. The time now is 03:43 AM.