Python smtplib module breaking arcpy?

Discussion created by smogmonster on Dec 17, 2012
Latest reply on Dec 17, 2012 by csny490

In my organization we have Python scripts used for data checks, which use ArcPy (ArcGIS 10.0 SP4) and also the smtplib modul,e so we can receive automated emails regarding data errors.

Problem we are finding is if try these scripts on our laptops. Not only cannot get script to connect to email server (which is not a problem I expect help for here), but it also semi-permanently breaking ArcPy AFTER failing to connect to email server via smtp module. I cannot understand why the two are linked? Simplest case from command prompt:


Python 2.6.5 (r265:79096, Mar 19 2010, 21:48:26) [MSC v.1500 32 bit (Intel)] on


Type "help", "copyright", "credits" or "license" for more information.

>>> import smtplib

>>> server=smtplib.SMTP('<MAIL SERVER>') 

Traceback (most recent call last):

  File "<stdin>", line 1, in <module>

  File "C:\Python26\lib\", line 239, in __init__

    (code, msg) = self.connect(host, port)

  File "C:\Python26\lib\", line 295, in connect

    self.sock = self._get_socket(host, port, self.timeout)

  File "C:\Python26\lib\", line 273, in _get_socket

    return socket.create_connection((port, host), timeout)

  File "C:\Python26\lib\", line 514, in create_connection

    raise error, msg

socket.error: [Errno 10061] No connection could be made because the target machine actively refused it

>>> import arcpy
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Program Files\ArcGIS\Desktop10.0\arcpy\arcpy\", line 17, i
n <module>
    from geoprocessing import gp
  File "C:\Program Files\ArcGIS\Desktop10.0\arcpy\arcpy\geoprocessing\__init__.p
y", line 14, in <module>
    from _base import *
  File "C:\Program Files\ArcGIS\Desktop10.0\arcpy\arcpy\geoprocessing\",
 line 568, in <module>
    env = GPEnvironments(gp)
  File "C:\Program Files\ArcGIS\Desktop10.0\arcpy\arcpy\geoprocessing\",
 line 565, in GPEnvironments
    return GPEnvironment(geoprocessor)
  File "C:\Program Files\ArcGIS\Desktop10.0\arcpy\arcpy\geoprocessing\",
 line 521, in __init__
  File "C:\Program Files\ArcGIS\Desktop10.0\arcpy\arcpy\geoprocessing\",
 line 523, in _refresh
    envset = (set(env for env in self._gp.listEnvironments()))
RuntimeError: NotInitialized

Now, ArcPy is broken on this laptop, running any ArcPy script with or without smtplib module. If I tried a script from a Toolbox, or any script with import ArcPy it will fail with the above error. I can import arcgisscripting successfully, however.

Rebooting makes no difference, uninstalling Python and ArcGIS 10.0 makes no difference. However, over time (maybe a week or two) ArcPy returns.

I just wondered if anyone had experienced this? There is a definite link with smtplib causing the problem to the ArcPy module and have reproduced it on multiple laptops here, never desktop PCs where the same is fine. Thanks.