Exception handling for socket.error in Python 3.5/RStudio

shaunak.bangale at gmail.com shaunak.bangale at gmail.com
Fri Feb 19 13:07:41 EST 2016


On Monday, February 8, 2016 at 1:05:08 AM UTC-7, shaunak... at gmail.com wrote:
> On Sunday, February 7, 2016 at 1:23:32 AM UTC-7, dieter wrote:
> > Shaunak Bangale <shaunak.bangale at gmail.com> writes:
> > > ...
> > > 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())
> > > ...
> > > Error:
> > > except socket.error as e:
> > >                          ^
> > > SyntaxError: invalid syntax
> > 
> > Are you sure, that there is no invisible character at the end
> > of that line?
> > 
> > When I try code like the above (in PYthon 2.7), there is no
> > "SyntaxError":
> > 
> > >>> while(False):
> > ...     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())
> > ... 
> > >>> 
> > 
> > 
> > Another reason for your problem could be an older Python version.
> > The "as" construct as part of the "except" clause is a more recent
> > addition to Python.
> 
> Hi Dieter,
> 
> I typed that line again but didn't help. I am using Python 3.5.
-------------

Hi people, it finally worked. One problem was with the way modules were set up, so installed anacoda and using accessing it through PyCharm. It's working well now. Another problem was with the initiation command, had to renew the password and that's working too. I sincerely thank everyone here who tried to help me. :) 
Have a great weekend guys!

-Shaun


More information about the Python-list mailing list