def __request_data(self):
if self.__is_cache_valid():
return True
# requesting data
try:
# setting 5 sec timeouts for connect and read
r = requests.get(self.data_url, verify=False, allow_redirects=True, timeout=(5, 5))
except requests.ConnectionError as e:
print("Unable to connect to ", self.data_url, " error is ", e, file=sys.stderr)
return False
except requests.ConnectTimeout as e:
print("Timed out connection to ", self.data_url, " error is ", e, file=sys.stderr)
return False
except requests.ReadTimeout as e:
print("Timed out while reading data from ", self.data_url, " error is ", e, file=sys.stderr)
return False
if r.status_code == 200:
# got HTTP/200 for request - storing it in cache
try:
open(self.temp_file_name, mode="w").write(json.dumps(r.json()))
except IOError as e:
print("IO error while trying to store cache into file ", self.temp_file_name, " error is ",
e, file=sys.stderr)
return False
return True
else:
return False
zoomdata-metrics-collector.py 文件源码
python
阅读 31
收藏 0
点赞 0
评论 0
评论列表
文章目录