Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!1.eu.feeder.erje.net!bcyclone05.am1.xlned.com!bcyclone05.am1.xlned.com!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!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.046 X-Spam-Evidence: '*H*': 0.91; '*S*': 0.00; 'messages.': 0.05; 'python3': 0.07; 'subject:Error': 0.07; 'try:': 0.09; 'err:': 0.16; 'received:gmx.com': 0.16; 'import': 0.22; 'error': 0.23; 'errors.': 0.24; 'this:': 0.26; 'tried': 0.27; 'code': 0.31; 'text': 0.33; 'skip:# 10': 0.33; 'message.': 0.35; 'except': 0.35; 'skip:u 20': 0.35; 'but': 0.35; 'hi,': 0.36; 'two': 0.37; 'to:addr :python-list': 0.38; 'to:addr:python.org': 0.39; 'how': 0.40; 'skip:u 10': 0.60; 'name': 0.63; 'more': 0.64; 'received:74.208': 0.68; 'webpage': 0.68; 'cable': 0.84 MIME-Version: 1.0 From: "brandon wallace" To: python-list@python.org Subject: Try Except Specific Error Messages Content-Type: text/plain; charset=UTF-8 Date: Fri, 1 May 2015 01:27:52 +0200 Importance: normal Sensitivity: Normal Content-Transfer-Encoding: quoted-printable X-Priority: 3 X-Provags-ID: V03:K0:DBTyZfcfAG4PKKYE7zcjHvgeLhzZ8CXQP1IRXhOPTBX DNIyE4S3bM5mpyaDzVKw07URJxdJ2PHhN31CaV0eQAAuxZDyd4 icW/8ZLfBWpgm5EuyY8GyAgJ5BiVcccBcmDjlR2UA5m9bSYI4b tmYrZcpXZohhI4F2Q18tDnS9UlsnqFwLidRuSpP0/0BY3yNPU7 A82iwBfo1E+u5wacIBympyv6vo2O5ki0zqHQAMndd+8YNqHvlz s1QW2Fd4MkV4BsJGGfkldCcnF3VnJEdbgAdyjaRbWNJ3HLN2mr i0Cu+CxT4OFCcO5YHIFETivqHLk X-UI-Out-Filterresults: notjunk:1; X-Mailman-Approved-At: Sat, 02 May 2015 18:54:19 +0200 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ 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: 32 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1430585660 news.xs4all.nl 2969 [2001:888:2000:d::a6]:53631 X-Complaints-To: abuse@xs4all.nl X-Received-Bytes: 3326 X-Received-Body-CRC: 3580743387 Xref: csiph.com comp.lang.python:89781 Hi, =C2=A0 I am try to get more specific error messages using try/except=2E I ran this code with the cable unplugged to see the error message=2E I got= =20 #!/usr/bin/env python3 import urllib=2Erequest webpage =3D urllib=2Erequest=2Eurlopen("http://fakewebsite=2Ecom/") text =3D webpage=2Eread()=2Edecode("utf8") I got two errors=2E This: [=2E=2E=2E=2E] socket=2Egaierror: [Errno -2] Name or service not known and this: [=2E=2E=2E=2E] urllib=2Eerror=2EURLError: I tried this but got more error messages=2E try: webpage =3D urllib=2Erequest=2Eurlopen("http://fakewebsite=2Ecom/") text =3D webpage=2Eread()=2Edecode("utf8") except URLError as err: print("URLError: " + str(err)) How do I wrap urllib=2Erequest with try/except?