1 import re
2
3 import httplib2
4
5 import dap.lib
6 from dap.exceptions import ClientError
7
8
9 -def openurl(url, cache=None, username=None, password=None):
10 h = httplib2.Http(cache)
11 if username and password: h.add_credentials(username, password)
12
13 if dap.lib.VERBOSE: print url
14 resp, data = h.request(url, "GET", headers={'user-agent': dap.lib.USER_AGENT})
15
16
17 if resp.get("content-description") == "dods_error":
18
19 m = re.search('code = (?P<code>\d+);\s*message = "(?P<msg>.*)"', data, re.DOTALL | re.MULTILINE)
20 msg = 'Server error %(code)s: "%(msg)s"' % m.groupdict()
21 raise ClientError(msg)
22
23 return resp, data
24