(url: str, params: dict[str, str] | None = None, timeout: int = 30)
| 122 | |
| 123 | |
| 124 | def fetch_data_from_url(url: str, params: dict[str, str] | None = None, timeout: int = 30) -> str: |
| 125 | ssl_context = ssl.create_default_context() |
| 126 | ssl_context.check_hostname = False |
| 127 | ssl_context.verify_mode = ssl.CERT_NONE |
| 128 | |
| 129 | if params is not None: |
| 130 | encoded = urlencode(params) |
| 131 | full_url = f'{url}?{encoded}' |
| 132 | else: |
| 133 | full_url = url |
| 134 | |
| 135 | try: |
| 136 | response = urlopen(full_url, context=ssl_context, timeout=timeout) |
| 137 | data = response.read().decode('UTF-8') |
| 138 | return data |
| 139 | except URLError as e: |
| 140 | raise ValueError(f'Unable to fetch data from url: {url}\n{e}') |
| 141 | except Exception as e: |
| 142 | raise ValueError(f'Unexpected error when parsing response: {e}') |
| 143 | |
| 144 | |
| 145 | def calc_checksum(icmp_packet: bytes) -> int: |
no test coverage detected