Exception handling for socket.error in Python 3.5/RStudio

shaunak.bangale at gmail.com shaunak.bangale at gmail.com
Fri Feb 5 15:11:05 EST 2016


On Friday, February 5, 2016 at 1:08:11 PM UTC-7, Nathan Hilterbrand wrote:
> On Feb 5, 2016 15:01, <shaunak.bangale at 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
> > --
> > https://mail.python.org/mailman/listinfo/python-list
> 
> Looks like you are missing a colon after 'as e'...    .... as e:  might do
> the trick
> 
> Nathan

Hi Nathan,

Tried colon and a comma as well. Both did not work.



More information about the Python-list mailing list