Commits

David Mehringer authored e793c56e05f
check point

casatasks/src/private/task_getantposalma.py

Modified
1 1 from casatasks import casalog
2 2 from casatools import quanta
3 +import certifi
3 4 import json, os, shutil
5 +import ssl
4 6 from urllib import request
5 7 from urllib.error import HTTPError, URLError
6 8 from urllib.parse import urlencode, urlparse
7 9
8 10
9 11 def _is_valid_url_host(url):
10 12 parsed = urlparse(url)
11 13 return bool(parsed.netloc)
12 14
13 15
14 16 def _query(url):
15 17 myjson = None
16 18 response = None
17 19 try:
18 - with request.urlopen(url) as response:
20 + context = ssl.create_default_context(cafile=certifi.where())
21 + with request.urlopen(url, context=context, timeout=400) as response:
19 22 if response.status == 200:
20 23 myjson = response.read().decode('utf-8')
21 24 except HTTPError as e:
22 25 casalog.post(
23 26 f"Caught HTTPError: {e.code} {e.reason}: {e.read().decode('utf-8')}",
24 27 "WARN"
25 28 )
26 29 except URLError as e:
27 30 casalog.post(f"Caught URLError: {str(e)}", "WARN")
28 31 except Exception as e:
194 197 if _qa.ge(t_start, t_end):
195 198 raise ValueError(
196 199 f"Parameter tw, start time ({z[0]}) must be less than end time ({z[1]})."
197 200 )
198 201 parms["tw"] = tw
199 202 if snr < 0:
200 203 raise ValueError(f"Parameter snr ({snr}) must be non-negative.")
201 204 elif snr > 0:
202 205 parms["snr"] = snr
203 206 if search:
207 + parms['search'] = search
208 + """
204 209 if search in ["both_latest", "both_closest"]:
205 210 parms["search"] = search
206 211 else:
207 212 raise ValueError(
208 213 f"Parameter search (={search}) must have a value of either "
209 214 "'both_latest' or 'both_closest'."
210 215 )
216 + """
211 217 qs = f"?{urlencode(parms)}"
212 218 antpos = None
213 219 for h in hosts:
214 220 if not _is_valid_url_host(h):
215 221 raise ValueError(
216 222 f'Parameter hosts: {h} is not a valid host expressed as a URL.'
217 223 )
218 224 url = f"{h}/{qs}"
219 225 casalog.post(f"Trying {url} ...", "NORMAL")
220 226 antpos = _query(url)

Everything looks good. We'll let you know here if there's anything you should know about.

Add shortcut