Welcome to the VanDyke Software Forums

Join the discussion today!


Go Back   VanDyke Software Forums > Scripting

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 07-16-2013, 09:29 AM
DaveFlys DaveFlys is offline
Registered User
 
Join Date: Jan 2012
Posts: 15
Question ImportError on SMTPLIB

I am having trouble importing module smtplib into my SecureCRT scripts. I had this working before, but cannot seem to get it working on a clean install. SecureCRT reports "Error: No module named _socket".

I have installed Python 2.7.5 onto the system and I can see the _socket.pyd module in the DLLs folder of that installation. If I import the module from the Python IDLE, it imports and functions without any errors. I have also added the folder to the Windows 7 Path statement.

I am running the 32-bit version of SecureCRT 6.7.5.

How do I get SecureCRT to find the smtplib library?

Thanks,
David
Reply With Quote
  #2  
Old 07-16-2013, 09:53 AM
rtb rtb is offline
VanDyke Technical Support
 
Join Date: Aug 2008
Posts: 4,306
Hi David,

Have you tried to add the Python 2.7.5 locations to the system path that SecureCRT uses when trying to find modules?

Here is how to display the paths that SecureCRT currently uses.
import sys
crt.Dialog.MessageBox(str(sys.path))
Here is how to add paths if they are not already included (you will have to define strPath):
import sys
sys.path.insert(0, strPath)
__________________
--Todd

VanDyke Software
Technical Support
support@vandyke.com
505-332-5730
Reply With Quote
  #3  
Old 07-16-2013, 10:23 AM
DaveFlys DaveFlys is offline
Registered User
 
Join Date: Jan 2012
Posts: 15
python27.dll confict

Todd,

That was great information. I was able to determine that the path was not in the list and then add it.

Now I am getting this error on import:

Code:
ImportError

Error: Module use of python27.dll conflicts with this version of Python.
What do you think? Do I need to have the older 2.6 version of Python installed?

David
Reply With Quote
  #4  
Old 07-16-2013, 10:33 AM
rtb rtb is offline
VanDyke Technical Support
 
Join Date: Aug 2008
Posts: 4,306
Hi David,

My guess is that you will have to install Python 2.6 rather than 2.7. Do you get better results if you use Python 2.6?
__________________
--Todd

VanDyke Software
Technical Support
support@vandyke.com
505-332-5730
Reply With Quote
  #5  
Old 07-16-2013, 10:58 AM
DaveFlys DaveFlys is offline
Registered User
 
Join Date: Jan 2012
Posts: 15
Python 2.6 works

Todd,

Python 2.6 does work. Thanks so much for the rapid responses.

Any plans to add support for Python 2.7 or even Python 3 in the future?

Cheers,
David
Reply With Quote
  #6  
Old 07-16-2013, 11:24 AM
rtb rtb is offline
VanDyke Technical Support
 
Join Date: Aug 2008
Posts: 4,306
Hi David,

I am glad to hear that you got this working. Feel free to post exactly what you did for others to use in the future.

With regards to newer versions of Python in SecureCRT, this has not yet become a top priority for implementation, but I have created a feature request in our SecureCRT enhancement database to add support for Python 2.7 or 3.x. Should we do so in the future, we will post to this forum thread.

If you would like to be notified directly, please complete and submit the form at the following location:
Submit Feature Request
__________________
--Todd

VanDyke Software
Technical Support
support@vandyke.com
505-332-5730
Reply With Quote
  #7  
Old 01-11-2015, 10:41 AM
Tonatiuh Tonatiuh is offline
Registered User
 
Join Date: Jul 2006
Posts: 68
I have the same problem with SecureCRT 7.3.0 and Python 2.7.6: "Error: No module named _socket".

But my problem only appears when I run the script in Windows. The script runs well in Mac OSX.

If I execute the same import statement into the windows python interpreter, there is no error.

Both machines have Python 2.7.6. I installed the same version in Windows to equals the one preinstalled in Mac, precisely to avoid conflicts like this.

I have several SecureCRT vbscripts in the Windows machine which send emails and are working well, so that, the operating system SMTP component is working properly.
Attached Files
File Type: txt Instance-Test.py.txt (577 Bytes, 158 views)

Last edited by Tonatiuh; 01-11-2015 at 04:28 PM.
Reply With Quote
  #8  
Old 01-12-2015, 10:09 AM
rtb rtb is offline
VanDyke Technical Support
 
Join Date: Aug 2008
Posts: 4,306
Hi Tonatiuh,

SecureCRT on Windows does not include support for _socket.

As mentioned previously, we will post here if we add support for _socket in a future SecureCRT for Windows release.

Also, as mentioned previously in this forum thread, the solution was to install Python 2.6 rather than 2.7.

SecureCRT on Windows uses Python 2.6. SecureCRT 7.3.x on Mac uses Python 2.7.

If you install Python 2.6 on Windows, do you get better results?
__________________
--Todd

VanDyke Software
Technical Support
support@vandyke.com
505-332-5730
Reply With Quote
  #9  
Old 01-12-2015, 01:33 PM
Tonatiuh Tonatiuh is offline
Registered User
 
Join Date: Jul 2006
Posts: 68
I was reluctant to think that it was not solved in a better manner for today. That's why sent this message (looking for a solution, not for a workaround).

Ok. I have to downgrade the Windows Python. I hope this difference in versioning between Win and Mac (which are intended to run exactly the same scripts) would not be the source for other kind of issues.
Reply With Quote
  #10  
Old 01-12-2015, 01:55 PM
Tonatiuh Tonatiuh is offline
Registered User
 
Join Date: Jul 2006
Posts: 68
I have uninstalled Python 2.7.9 and have installed Python 2.6.6.

The error message is exactly the same.

If I change the line (in the script):
Code:
if "C:\\Python26" not in sys.path: sys.path.(0,"C:\\Python26")
By this:
Code:
if "C:\\Python26" not in sys.path: sys.path.append("C:\\Python26")
The error message change to "Error: DLL load failed: The specified module could not be found." and references to the line of the "import smtplib".
Reply With Quote
  #11  
Old 01-12-2015, 03:50 PM
rtb rtb is offline
VanDyke Technical Support
 
Join Date: Aug 2008
Posts: 4,306
Hi Tonatiuh,

Since you are not getting the behavior that is expected, perhaps it will be necessary to override the Python 2.6 that SecureCRT uses by default.

You can do this by renaming the following files:
python26.dll
python26.zip
You would want to rename them while SecureCRT is not running.

This will only work if you have Python 2.6 installed.

I haven't tested this with the smptlib module, but I have used the method for other modules that require _socket.

Does this help resolve the issue?

If not, what version of Windows are you using and is it 32-bit or 64-bit?
__________________
--Todd

VanDyke Software
Technical Support
support@vandyke.com
505-332-5730
Reply With Quote
  #12  
Old 01-12-2015, 05:39 PM
Tonatiuh Tonatiuh is offline
Registered User
 
Join Date: Jul 2006
Posts: 68
If the matter of this is the different versions, is not better to install exactly the same version that comes with SecureCRT? Which one is? 2.6.x?

I have Win 64-bits and installed Python for Win 64-bits.
Reply With Quote
  #13  
Old 01-13-2015, 11:34 AM
rtb rtb is offline
VanDyke Technical Support
 
Join Date: Aug 2008
Posts: 4,306
Hi Tonatiuh,

It doesn't matter based on my testing. I tested with Python 2.6.7 today, and in the past I tested with 2.6.6 and older variants. It just needs to be a version of 2.6.x.

If you rename the 2 files, you don't have to insert Python into the path. You just need to run the script normally.

Does this help?
__________________
--Todd

VanDyke Software
Technical Support
support@vandyke.com
505-332-5730
Reply With Quote
  #14  
Old 01-13-2015, 01:46 PM
Tonatiuh Tonatiuh is offline
Registered User
 
Join Date: Jul 2006
Posts: 68
Hi,

The import is working know, but I the script hangs apparently in the "smtplib.SMTP("smtp.gmail.com", 465)". The lines above this line excute properly.

The script does not return any error, but it hags. I cannot event "Cancel" because its status does not change. I have to close the CRT session to be able to interrupt the hanged execution of the script.

I have tested the machine with vbs send mail script, and executing "telnet smtp.gmail.com 465", both successfully.

The behavior is exactly the same in Win and Mac.

Last edited by Tonatiuh; 01-14-2015 at 10:27 AM.
Reply With Quote
  #15  
Old 01-13-2015, 05:27 PM
rtb rtb is offline
VanDyke Technical Support
 
Join Date: Aug 2008
Posts: 4,306
Hi Tonatiuh,

I was able to get the following code to work from within SecureCRT:
Code:
# $language = "python"
# $interface = "1.0"

import smtplib

def Main():
    mailMsg = smtplib.SMTP("[SMPT_SERVER]", [PORT])
    mailMsg.sendmail("[FROM_EMAIL_ADDRESS]", "[TO_EMAIL_ADDRESS]", "This is a test")

Main()
You may consider using a different SMTP server or making sure that your connect code is configured correctly.

Perhaps the SMTP server you are using require credentials to connect.
__________________
--Todd

VanDyke Software
Technical Support
support@vandyke.com
505-332-5730
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
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 08:52 PM.