Exception handling for socket.error in Python 3.5/RStudio
rosuav at gmail.com
Fri Feb 5 21:04:19 EST 2016
On Sat, Feb 6, 2016 at 9:35 AM, <shaunak.bangale at gmail.com> wrote:
> On Friday, February 5, 2016 at 12:58:37 PM UTC-7, shaunak... 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:
>> # parse
>> count = count - 1
>> except socket.error as e
>> print('Connection fail', e)
>> # wait for user input to end
>> # input("\n Press Enter to exit...");
>> # close the SSLSocket, will also close the underlying socket
>> 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.
> 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?
(Please quote the person you're replying to, rather than simply
quoting your own original post - it helps to provide context. Thanks!)
The next thing to try would be to add the colon at the end of the
"except" clause, as has already been suggested, and then to post the
latest code (preferably all of it - if it looks like too much, it's
worth shortening the code, rather than posting a snippet) and the full
More information about the Python-list