X-Received: by 10.66.122.2 with SMTP id lo2mr14741957pab.33.1454711706834; Fri, 05 Feb 2016 14:35:06 -0800 (PST) X-Received: by 10.50.114.132 with SMTP id jg4mr480221igb.1.1454711706799; Fri, 05 Feb 2016 14:35:06 -0800 (PST) Path: csiph.com!optima2.xanadu-bbs.net!xanadu-bbs.net!news.glorb.com!o2no2533653iga.0!news-out.google.com!l1ni4127igd.0!nntp.google.com!o2no2533644iga.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.python Date: Fri, 5 Feb 2016 14:35:06 -0800 (PST) In-Reply-To: <1067e50c-bcbd-464e-8013-754bd66fda91@googlegroups.com> Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=199.64.7.55; posting-account=GQSwwAoAAADdzyJmp7OY2kz4lgX4KZa_ NNTP-Posting-Host: 199.64.7.55 References: <1067e50c-bcbd-464e-8013-754bd66fda91@googlegroups.com> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: Subject: Re: Exception handling for socket.error in Python 3.5/RStudio From: shaunak.bangale@gmail.com Injection-Date: Fri, 05 Feb 2016 22:35:06 +0000 Content-Type: text/plain; charset=ISO-8859-1 Xref: csiph.com comp.lang.python:102567 On Friday, February 5, 2016 at 12:58:37 PM UTC-7, shaunak...@gmail.com wrote: > I am running this python script on R-studio. I have Python 3.5 installed on my system. > > count = 10 > while (count > 0): > try : > # read line from file: > print(file.readline()) > # parse > parse_json(file.readline()) > count = count - 1 > except socket.error as e > print('Connection fail', e) > print(traceback.format_exc()) > > # wait for user input to end > # input("\n Press Enter to exit..."); > # close the SSLSocket, will also close the underlying socket > ssl_sock.close() > The error I am getting is here: > > line 53 except socket.error as e ^ SyntaxError: invalid syntax > > I tried changing socket.error to ConnectionRefusedError. and still got the same error. > > Please tell me if the problem is with Rstudio, Python version or the syntax. > > TIA > -Shaunak Chris, That sounds legitimate. But I never installed second 3.X version and deleted previous 2.X version and using only 3.5 now. What will be the next test according to you? -Shaun