python3中处理url异常

 1 import urllib.request
 2 import urllib.error
 3 
 4 url = 'http://c.telunyun.com/Chart/getJsonData?market=1'
 5 data = urllib.request.Request(url)
 6 try:
 7     data = urllib.request.urlopen(data)
 8     print(data.read().decode('utf-8'))
 9 except urllib.error.URLError as e:
10     print (e.code)
11     print (e.read().decode('utf-8'))

 

posted on 2017-03-08 00:33  Perl6  阅读(1224)  评论(0编辑  收藏  举报

导航