Python 网络检查不断失败

Python 网络检查不断失败,python,import,health-check,Python,Import,Health Check,我正试图让我导入到health_checks.py的网络模块通过一切正常,但它一直失败。该模块本身就可以工作,但我正在尝试打印check_localhost和check_cpu_usage,但它仍然没有打印任何内容。因此,我目前无法调试代码来修复它并找出错误所在,因为每次运行health_checks.py脚本时,它都会返回“network checks failed” health_checks.py脚本的代码: #!/usr/bin/env python3 from network impo

我正试图让我导入到health_checks.py的网络模块通过一切正常,但它一直失败。该模块本身就可以工作,但我正在尝试打印check_localhost和check_cpu_usage,但它仍然没有打印任何内容。因此,我目前无法调试代码来修复它并找出错误所在,因为每次运行health_checks.py脚本时,它都会返回“network checks failed”

health_checks.py脚本的代码:

#!/usr/bin/env python3
from network import *
import shutil
import psutil
def check_disk_usage(disk):
    """Verifies that there's enough free space on disk"""
    du = shutil.disk_usage(disk)
    free = du.free / du.total * 100
    return free > 20
def check_cpu_usage():
    """Verifies that there's enough unused CPU"""
    usage = psutil.cpu_percent(1)
    return usage < 75
# If there's not enough disk, or not enough CPU, print an error
if not check_disk_usage('/') or not check_cpu_usage():
    print("ERROR!")
elif check_localhost() and check_connectivity():
    print("Everything ok")
    print(check_localhost())
    print(check_cpu_usage())
else:
    print("network checks failed")
我不知道这是一个导入问题还是一个内部脚本问题,任何帮助将不胜感激,谢谢

#!/usr/bin/env python3
import requests
import socket
def check_localhost():
   localhost = socket.gethostbyname('localhost')
   if localhost == '127.0.0.1':
    return localhost
   print(localhost)
def check_connectivity():
   request = requests.get("http://www.google.com")
   response = request.status_code
   if response == '200':
    return response
   print(response)