試圖做一個簡單的錯誤處理,看看主機是否無法訪問,我一直得到一個無效的語法except。錯誤處理python
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()
規則:每當你得到一個奇怪的語法錯誤,看看在*之前*網上看到如果括號,括號和括號是平衡的。 –