Welcome to the VanDyke Software Forums

Join the discussion today!


Go Back   VanDyke Software Forums > Scripting

Notices

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 03-24-2021, 02:58 PM
JerelH's Avatar
JerelH JerelH is offline
Registered User
 
Join Date: Jul 2017
Posts: 3
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
Reply With Quote
  #2  
Old 03-24-2021, 09:13 PM
jdev's Avatar
jdev jdev is offline
VanDyke Technical Support
 
Join Date: Nov 2003
Location: Albuquerque, NM
Posts: 1,099
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
__________________
Jake Devenport
VanDyke Software
Technical Support
YouTube Channel: https://www.youtube.com/vandykesoftware
Email: support@vandyke.com
Web: https://www.vandyke.com/support
Reply With Quote
  #3  
Old 03-24-2021, 09:57 PM
JerelH's Avatar
JerelH JerelH is offline
Registered User
 
Join Date: Jul 2017
Posts: 3
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.
Reply With Quote
  #4  
Old 03-25-2021, 02:16 PM
jdev's Avatar
jdev jdev is offline
VanDyke Technical Support
 
Join Date: Nov 2003
Location: Albuquerque, NM
Posts: 1,099
Quote:
Originally Posted by JerelH View Post
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 View Post
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
__________________
Jake Devenport
VanDyke Software
Technical Support
YouTube Channel: https://www.youtube.com/vandykesoftware
Email: support@vandyke.com
Web: https://www.vandyke.com/support
Reply With Quote
  #5  
Old 03-25-2021, 03:33 PM
JerelH's Avatar
JerelH JerelH is offline
Registered User
 
Join Date: Jul 2017
Posts: 3
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.
Attached Files
File Type: txt py3ImportArbitraryDataFromFileToSecureCRTSessions.py.txt (47.8 KB, 420 views)
Reply With Quote
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -6. The time now is 05:23 PM.