Stacy (and others),Yes, it's a work computer related issue. I've tried this at home on my personal computer and it has worked perfectly. Now for the difficult bit - trying to get an answer from the work IT people!Thanks again for your help and I'll be following your blog.Mal
Malcolm,Some googling revealed that your problem may be to do with a firewall -...If you are using a workplace computer it may be that your workplace has some kind of firewall that is blocking your connection to gmail (but if you can access gmail from your workplace, this probably isn't the case)...
Here is a way you can do it; writes the text file and sends an email. The trickiest bit is getting it to work with your specific SMTP email server. If you have gmail it's easy as pie; if not - google around......Let me know how you get on.
socket.error: [Errno 10061] No connection could be made because the target machine actively refused it
On a side note does anyone know of any good websites, or any good books related to both Python and ArcGIS? One of these days I need to breakdown and just learn it I think.
import smtplib import arcpy ### This is the module that does the sending - you should only need to edit the top four active lines def sendResultEmail(msgContents, success_TF): to = 'receiver@email.com' send_username = 'sender@email.com' send_password = 'password' # warning - will just be an unencrypted string - so be careful not to leave this file lying around! # This is the tricky bit - here are the settings for gmail (which will only work if your sender is gmail and you have a gmail account). # If you are using something else, google around smtplib and the email service you use. # I would suggest gmail is probably a pretty good start if you have an account... smtpserver = smtplib.SMTP("smtp.gmail.com",587) if success_TF: subject = 'Arcpy testing results: script SUCCESS.' else: subject = 'Arcpy testing results: script FAILURE.' smtpserver.ehlo() smtpserver.starttls() smtpserver.ehlo smtpserver.login(send_username, send_password) header = 'To:' + to + '\n' + 'From: ' + send_username + '\n' + 'Subject:' + subject + '\n' msg = header + '\nArcpy results: \n\t' + msgContents + '\n' smtpserver.sendmail(send_username, to, msg) arcpy.AddMessage('Results email sent!') smtpserver.close() ### Here is the geoprocessing code; add to strResult every time you need to add something to the message (i.e. completion times) ### In a complex code this could be a lot of information, so seperate with '\n' to force new lines in the text... inFC = arcpy.GetParameterAsText(0) outLoc = arcpy.GetParameterAsText(1) outFC = arcpy.GetParameterAsText(2) success = False # assume failure (changed to True if script is successful) strResult = '' # start empty string - write to this, for saving to text file and sending to email try: arcpy.FeatureClassToFeatureClass_conversion(inFC, outLoc, outFC) strResult += "Converted successfully \n" success = True except arcpy.ExecuteError: strResult += arcpy.GetMessages() arcpy.AddMessage(strResult) # Now write results to the text file outtable = open(r"C:\temp\results.txt", "w") outtable.write(strResult) outtable.close() # Now send the email. This line calls the module above, passing it the string and the T/F success variable... sendResultEmail(strResult, success)
Thank you so much .. that is working perfectly for me!
import arcpy, os from arcpy import env env.workspace = r"c:\temp\python\test.gdb" outtable = open(r"C:\temp\results.txt", "w") try: arcpy.FeatureClassToFeatureClass_conversion("Airports", env.workspace, "Airports2") outtable.write("Converted successfully") except arcpy.ExecuteError: outtable.write(arcpy.GetMessages()) outtable.close()
Signed in members can post, follow updates, and more. New here? Register a free account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.