Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.fsmpi.rwth-aachen.de!weretis.net!feeder4.news.weretis.net!ecngs!feeder2.ecngs.de!novso.com!newsfeed.xs4all.nl!newsfeed4a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.008 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'none,': 0.07; 'subject:Getting': 0.07; '__init__': 0.09; 'archiving': 0.09; 'below).': 0.09; 'debugger': 0.09; 'executed': 0.09; 'none)': 0.09; 'try:': 0.09; 'python': 0.11; '2.7': 0.14; 'function?': 0.16; 'port)': 0.16; 'self.sock': 0.16; 'skip:" 70': 0.16; 'all.': 0.16; 'file,': 0.19; 'import': 0.22; 'print': 0.22; 'error': 0.23; 'connected': 0.24; 'script': 0.25; '(see': 0.26; 'skip:" 30': 0.26; 'code:': 0.26; 'host': 0.29; 'raise': 0.29; "doesn't": 0.30; "skip:' 10": 0.31; 'file': 0.32; 'skip:c 30': 0.32; 'run': 0.32; 'open': 0.33; 'worked': 0.33; '(most': 0.33; 'mac': 0.33; 'skip:_ 10': 0.34; 'skip:d 20': 0.34; 'subject:from': 0.34; 'except': 0.35; 'skip:s 30': 0.35; 'but': 0.35; 'hi,': 0.36; 'error.': 0.37; 'gmail': 0.38; 'to:addr:python-list': 0.38; 'recent': 0.39; 'to:addr:python.org': 0.39; 'skip:p 20': 0.39; 'how': 0.40; 'simple': 0.61; 'first': 0.61; 'header:Message-Id:1': 0.63; 'myself': 0.63; 'received:79': 0.64; 'talking': 0.65; 'from:addr:mail': 0.83; '3.4': 0.84; 'received:212.162': 0.84; 'route': 0.84; 'capture': 0.91 From: Beatrix Willius from Moth Software Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Subject: Getting errors from Imaplib Date: Sun, 30 Nov 2014 09:36:33 +0100 To: python-list@python.org Mime-Version: 1.0 (Mac OS X Mail 8.0 \(1990.1\)) X-Mailer: Apple Mail (2.1990.1) X-Info: valid message X-Info: original Date X-Mailman-Approved-At: Sun, 30 Nov 2014 12:43:44 +0100 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 69 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1417347825 news.xs4all.nl 2853 [2001:888:2000:d::a6]:60414 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:81729 Hi, first poster here. I still consider myself pretty much a Python newbie. Let's say I have the following very simple Python code: import imaplib host =3D 'imap.gmail.com' try: imap_connection =3D imaplib.IMAP4(host) print('success') except imaplib.IMAP4.error: print('authentication failed') Now, Gmail doesn't like non-ssl connections. In this case I only want to = return an error. This worked for Pyhton 2.7 but in Python 3.4 I only get = a traceback (see below). The line print('authentication failed') is not = executed at all. How do I capture the error for using the print = function? Mac OS 10.10. Python 3.4.1. The script is part of a larger one that is = talking to my Xojo application. Connected to pydev debugger (build 135.1057) Traceback (most recent call last): File "/Applications/Develop/PyCharm CE.app/helpers/pydev/pydevd.py", = line 1733, in debugger.run(setup['file'], None, None) File "/Applications/Develop/PyCharm CE.app/helpers/pydev/pydevd.py", = line 1226, in run pydev_imports.execfile(file, globals, locals) # execute the script File "/Applications/Develop/PyCharm = CE.app/helpers/pydev/_pydev_execfile.py", line 38, in execfile exec(compile(contents+"\n", file, 'exec'), glob, loc) #execute the = script File "/Users/beatrixwillius/Documents/ Datei/Development/Mail = Archiver/Projects/MainClasses Projects/imap/test/test.py", line 6, in = imap_connection =3D imaplib.IMAP4(host) File = "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/imaplib.p= y", line 181, in __init__ self.open(host, port) File = "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/imaplib.p= y", line 257, in open self.sock =3D self._create_socket() File = "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/imaplib.p= y", line 247, in _create_socket return socket.create_connection((self.host, self.port)) File = "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/socket.py= ", line 509, in create_connection raise err File = "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/socket.py= ", line 500, in create_connection sock.connect(sa) OSError: [Errno 65] No route to host Mit freundlichen Gr=C3=BC=C3=9Fen/Regards Trixi Willius http://www.mothsoftware.com Mail Archiver X: The email archiving solution for professionals