diff --git a/respodns/ip_info.py b/respodns/ip_info.py index 1abab39..365a2a8 100644 --- a/respodns/ip_info.py +++ b/respodns/ip_info.py @@ -36,6 +36,9 @@ class IpInfoByIpApi(IpInfoBase): def _parse_headers(self, it): # returns an error message as a string, or None. + x_cooldown = None + x_remaining = None + for line in it: if line == b"": break # end of header @@ -106,27 +109,17 @@ class IpInfoByIpApi(IpInfoBase): response = await reader.read() lines = response.splitlines() - err = None it = iter(lines) - - line = next(it) - if line != b"HTTP/1.1 200 OK": - self.cooldown = time() + 60 - err = "not ok" - it = () # exhaust iterator (not really) - - x_cooldown = None - x_remaining = None - - if err is None: + if next(it, None) == b"HTTP/1.1 200 OK": err = self._parse_headers(it) - - for i, line in enumerate(it): - if i == 0: - code = line - else: + code = next(it, None) + if code is None: + err = "missing body" + if next(it, None) is not None: err = "too many lines" - break + else: + err = "not ok" + self.cooldown = time() + 60 writer.close()