Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #89781
| 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 | <nodnarb@gmx.us> |
| 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" <nodnarb@gmx.us> |
| 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 <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> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.18.1430585660.12865.python-list@python.org> (permalink) |
| 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 |
Show key headers only | View raw
Hi,
I am try to get more specific error messages using try/except.
I ran this code with the cable unplugged to see the error message. I got
#!/usr/bin/env python3
import urllib.request
webpage = urllib.request.urlopen("http://fakewebsite.com/")
text = webpage.read().decode("utf8")
I got two errors. This:
[....]
socket.gaierror: [Errno -2] Name or service not known
and this:
[....]
urllib.error.URLError: <urlopen error [Errno -2] Name or service not known>
I tried this but got more error messages.
try:
webpage = urllib.request.urlopen("http://fakewebsite.com/")
text = webpage.read().decode("utf8")
except URLError as err:
print("URLError: " + str(err))
How do I wrap urllib.request with try/except?
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Try Except Specific Error Messages "brandon wallace" <nodnarb@gmx.us> - 2015-05-01 01:27 +0200
csiph-web