Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #102618

Re: Exception handling for socket.error in Python 3.5/RStudio

Path csiph.com!2.eu.feeder.erje.net!feeder.erje.net!1.eu.feeder.erje.net!newsfeed.freenet.ag!newsfeed.kamp.net!newsfeed.kamp.net!fu-berlin.de!uni-berlin.de!not-for-mail
From dieter <dieter@handshake.de>
Newsgroups comp.lang.python
Subject Re: Exception handling for socket.error in Python 3.5/RStudio
Date Sun, 07 Feb 2016 09:23:04 +0100
Lines 42
Message-ID <mailman.64.1454833396.2317.python-list@python.org> (permalink)
References <1067e50c-bcbd-464e-8013-754bd66fda91@googlegroups.com> <alpine.LSU.2.11.1602051237120.2025@znpeba.jbaqresebt.arg> <CALqmhqodOPdebFA_Zmj1fiX3r=L=cHZDU=oc=4xmq+3sJaMG6w@mail.gmail.com>
Mime-Version 1.0
Content-Type text/plain; charset=us-ascii
X-Trace news.uni-berlin.de rdv/Vqtn1HUIc1LEbgSITQB3NPceS0+VvmgSOttclXdQ==
Cancel-Lock sha1:51blYbYPgIIqLQMvCndFXvHVoG0=
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'subject:Python': 0.05; 'error:': 0.05; 'clause': 0.07; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'socket.error': 0.09; 'python': 0.10; 'python.': 0.11; 'syntax': 0.13; '0):': 0.16; 'invisible': 0.16; 'received:80.91.229.3': 0.16; 'received:dip0.t-ipconnect.de': 0.16; 'received:io': 0.16; 'received:plane.gmane.org': 0.16; 'received:psf.io': 0.16; 'received:t-ipconnect.de': 0.16; 'subject:handling': 0.16; 'syntaxerror:': 0.16; 'version.': 0.18; '(in': 0.18; '>>>': 0.20; 'file:': 0.22; 'parse': 0.22; 'header :User-Agent:1': 0.26; 'header:X-Complaints-To:1': 0.26; 'sure,': 0.29; 'character': 0.29; 'subject:/': 0.30; 'code': 0.30; 'another': 0.32; 'older': 0.32; 'problem': 0.33; 'except': 0.34; 'could': 0.35; 'there': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'received:org': 0.37; 'charset:us-ascii': 0.37; 'skip:p 20': 0.38; 'end': 0.39; 'to:addr:python.org': 0.40; 'received:de': 0.40; 'your': 0.60; 'more': 0.63; 'received:217': 0.66; 'construct': 0.84
X-Injected-Via-Gmane http://gmane.org/
X-Gmane-NNTP-Posting-Host pd9e09138.dip0.t-ipconnect.de
User-Agent Gnus/5.1008 (Gnus v5.10.8) XEmacs/21.4.22 (linux)
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.21rc2
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Xref csiph.com comp.lang.python:102618

Show key headers only | View raw


Shaunak Bangale <shaunak.bangale@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.

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Exception handling for socket.error in Python 3.5/RStudio shaunak.bangale@gmail.com - 2016-02-05 11:58 -0800
  Re: Exception handling for socket.error in Python 3.5/RStudio Nathan Hilterbrand <nhilterbrand@gmail.com> - 2016-02-05 15:07 -0500
    Re: Exception handling for socket.error in Python 3.5/RStudio shaunak.bangale@gmail.com - 2016-02-05 12:11 -0800
      Re: Exception handling for socket.error in Python 3.5/RStudio shaunak.bangale@gmail.com - 2016-02-05 12:17 -0800
  Re: Exception handling for socket.error in Python 3.5/RStudio "Martin A. Brown" <martin@linux-ip.net> - 2016-02-05 12:08 -0800
    Re: Exception handling for socket.error in Python 3.5/RStudio shaunak.bangale@gmail.com - 2016-02-05 12:22 -0800
  Re: Exception handling for socket.error in Python 3.5/RStudio "Martin A. Brown" <martin@linux-ip.net> - 2016-02-05 12:44 -0800
  Re: Exception handling for socket.error in Python 3.5/RStudio "Martin A. Brown" <martin@linux-ip.net> - 2016-02-05 13:01 -0800
  Re: Exception handling for socket.error in Python 3.5/RStudio Chris Angelico <rosuav@gmail.com> - 2016-02-06 08:01 +1100
  Re: Exception handling for socket.error in Python 3.5/RStudio Bernardo Sulzbach <mafagafogigante@gmail.com> - 2016-02-05 19:08 -0200
    Re: Exception handling for socket.error in Python 3.5/RStudio shaunak.bangale@gmail.com - 2016-02-05 13:26 -0800
      Re: Exception handling for socket.error in Python 3.5/RStudio Bernardo Sulzbach <mafagafogigante@gmail.com> - 2016-02-05 19:37 -0200
  Re: Exception handling for socket.error in Python 3.5/RStudio shaunak.bangale@gmail.com - 2016-02-05 13:57 -0800
  Re: Exception handling for socket.error in Python 3.5/RStudio Chris Angelico <rosuav@gmail.com> - 2016-02-06 08:57 +1100
  Re: Exception handling for socket.error in Python 3.5/RStudio shaunak.bangale@gmail.com - 2016-02-05 14:35 -0800
    Re: Exception handling for socket.error in Python 3.5/RStudio Chris Angelico <rosuav@gmail.com> - 2016-02-06 13:04 +1100
  Re: Exception handling for socket.error in Python 3.5/RStudio Shaunak Bangale <shaunak.bangale@gmail.com> - 2016-02-05 13:50 -0700
  Re: Exception handling for socket.error in Python 3.5/RStudio Shaunak Bangale <shaunak.bangale@gmail.com> - 2016-02-05 14:00 -0700
  Re: Exception handling for socket.error in Python 3.5/RStudio Shaunak Bangale <shaunak.bangale@gmail.com> - 2016-02-05 14:15 -0700
  Re: Exception handling for socket.error in Python 3.5/RStudio dieter <dieter@handshake.de> - 2016-02-07 09:23 +0100
    Re: Exception handling for socket.error in Python 3.5/RStudio shaunak.bangale@gmail.com - 2016-02-08 00:04 -0800
      Re: Exception handling for socket.error in Python 3.5/RStudio shaunak.bangale@gmail.com - 2016-02-19 10:07 -0800

csiph-web