Read the specified endpoint and return the results.
(addr, endpoint, query=None)
| 30 | |
| 31 | |
| 32 | def read_endpoint(addr, endpoint, query=None): |
| 33 | """ |
| 34 | Read the specified endpoint and return the results. |
| 35 | """ |
| 36 | try: |
| 37 | addr = cli.util.sanitize_address(addr) |
| 38 | except Exception as exception: |
| 39 | raise CLIException("Unable to sanitize address '{addr}': {error}" |
| 40 | .format(addr=addr, error=str(exception))) |
| 41 | |
| 42 | try: |
| 43 | url = "{addr}/{endpoint}".format(addr=addr, endpoint=endpoint) |
| 44 | if query is not None: |
| 45 | url += "?{query}".format(query=urllib.parse.urlencode(query)) |
| 46 | http_response = urllib.request.urlopen(url).read().decode("utf-8") |
| 47 | except Exception as exception: |
| 48 | raise CLIException("Unable to open url '{url}': {error}" |
| 49 | .format(url=url, error=str(exception))) |
| 50 | |
| 51 | return http_response |
| 52 | |
| 53 | |
| 54 | def get_json(addr, endpoint, condition=None, timeout=5, query=None): |
no test coverage detected