Python returns False even if internet is connected

前端 未结 2 2079
天涯浪人
天涯浪人 2021-01-23 09:22

I am trying to learn python. This a script I wrote to check internet connection

import os
import urllib2
from time import sleep
REMOTE_SERVER = \"www.google.co.u         


        
2条回答
  •  礼貌的吻别
    2021-01-23 10:06

    Since you haven't imported socket, your reference to socket.gethostbyname will fail with a NameError. But you're catching and silencing every single exception in your try/except block, including that very error. You should never ever do a blank except in the first place, and especially never just to have pass.

    Remove that try/except, or limit it to exceptions you know you can handle.

提交回复
热议问题