[英]Error handling python
Trying to do a simple error handling to see if the host is unreachable and I keep getting an invalid syntax on except. 尝试做一个简单的错误处理,以查看主机是否无法访问,并且除之外,我一直收到无效的语法。
import socket
s = socket.socket()
host = ""
port = 1337
print("""
============================================
Welcome to Coder77's local internet messager
============================================
The current soon to be encrypted server is {0}
""".format(host))
host = input("Please select the IP you would like to communicate to: ")
print("Now connecting to {0}....".format(host))
try:
s.connect((host, port)
except socket.error as s:
print ("Host is unreachable")
print (s.recv(2048))
input("Close")
s.close()
将s.connect((host, port)
更改为s.connect(host, port)
s.connect((host, port)
应该
s.connect((host, port))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.