社区所有版块导航
Python
python开源   Django   Python   DjangoApp   pycharm  
DATA
docker   Elasticsearch  
aigc
aigc   chatgpt  
WEB开发
linux   MongoDB   Redis   DATABASE   NGINX   其他Web框架   web工具   zookeeper   tornado   NoSql   Bootstrap   js   peewee   Git   bottle   IE   MQ   Jquery  
机器学习
机器学习算法  
Python88.com
反馈   公告   社区推广  
产品
短视频  
印度
印度  
Py学习  »  Python

当我在google python上ping端口443时,python说它关闭了[复制]

John Tobey • 6 年前 • 1839 次点击  

我正在努力学习蟒蛇。这是我写的检查互联网连接的脚本

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

def is_connected():
  try:
    # see if we can resolve the host name -- tells us if there is
    # a DNS listening
    host = socket.gethostbyname(REMOTE_SERVER)
    # connect to the host -- tells us if the host is actually
    # reachable
    s = socket.create_connection((host, 80), 2)
    return True
  except:
     pass
  return False

while(1):
   if is_connected()  == False:
     print is_connected()
   sleep(10)

问题是,即使我连接到Internet,此脚本也会返回false。我可以ping www. GoGoel.C.U.K.但是这个脚本只是返回false。有什么想法吗????

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/43408
 
1839 次点击  
文章 [ 2 ]  |  最新文章 6 年前