Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: 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; 'python,': 0.02; 'subject:error': 0.03; 'cpython': 0.05; 'socket': 0.07; 'subject:reset': 0.07; 'builtin': 0.09; 'subject:peer': 0.09; 'subject:How': 0.10; 'python': 0.11; 'windows': 0.15; '3.3,': 0.16; 'attribute.': 0.16; 'errno': 0.16; 'exception:': 0.16; 'keyword.': 0.16; 'oserror': 0.16; 'wrote:': 0.18; 'reset': 0.22; 'header:User-Agent:1': 0.23; 'error': 0.23; 'earlier': 0.24; 'versions': 0.24; 'purposes': 0.26; 'header:In-Reply-To:1': 0.27; 'testing': 0.29; 'raise': 0.29; 'code': 0.31; 'exceptions': 0.31; 'raised': 0.31; 'url:python': 0.33; 'test': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'url:org': 0.36; 'error.': 0.37; 'message-id:@gmail.com': 0.38; 'url:library': 0.38; 'handle': 0.38; 'to:addr:python-list': 0.38; 'sure': 0.39; 'to:addr:python.org': 0.39; 'how': 0.40; 'subject:"': 0.60; 'url:3': 0.61; '9.1': 0.84; 'freebsd': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:subject:references :in-reply-to:x-enigmail-version:content-type :content-transfer-encoding; bh=6hKyh//UYVU8l3oWgTlaUmIJni5yShVlEUC94f2A1NY=; b=UNqHPlx2OcnPtHhScTxxAH9ohITKT+EVxZWld0AepN5LqeU59x766SX5WUCbhf1FFq 7ZSOQCqoCeW+O0vViV68VM4o30EyjeUwNDVf/rEusyu9Rqbi1revDTV0ZIHbexQfWUR8 DPsVXX5KxWzFRJLwQOKhqb1vnFw/7WMoWlg4Opb/HCyQ8bNambQ/4m3jkJ2mNsUEE8ru 9NR6eDOi9+OGISGaueEH6UYMSlAOtNxT/xPHA0iRRMLe+IGjQ+fZBOsC05uIa9Vfincs 252FjzTRjejV2AyfMX17rl2U6QT73AxgEW97NwTSTglv/Ea9zlKrdoUWOYU/OFvEhZSQ 5hwg== X-Received: by 10.50.3.67 with SMTP id a3mr1786815iga.88.1369151373951; Tue, 21 May 2013 08:49:33 -0700 (PDT) Date: Tue, 21 May 2013 10:49:31 -0500 From: Andrew Berg User-Agent: Mozilla/5.0 (Windows NT 6.2; WOW64; rv:17.0) Gecko/20130107 Thunderbird/17.0.2 MIME-Version: 1.0 To: "comp.lang.python" Subject: Re: How to raise a socket "104 connection reset by peer error" References: In-Reply-To: X-Enigmail-Version: 1.5.1 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 10 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1369151377 news.xs4all.nl 15909 [2001:888:2000:d::a6]:45590 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:45674 On 2013.05.21 10:26, loial wrote: > For testing purposes I want my code to raise a socket "connection reset by peer" error, so that I can test how I handle it, but I am not sure how to raise the error. Arbitrary exceptions can be raised with the raise keyword. In Python 3.3, that exact error got its own builtin exception: http://docs.python.org/3.3/tutorial/errors.html#raising-exceptions http://docs.python.org/3.3/library/exceptions.html#ConnectionResetError In earlier versions of Python, you will have to raise OSError and set its errno attribute. -- CPython 3.3.2 | Windows NT 6.2.9200 / FreeBSD 9.1