我创建了这个python脚本:
#!/usr/bin/python
#-*- coding: utf-8 -*-
import socket
connexion = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
host = input("Ip :")
port = int(input("Port :"))
connexion.connect(host, port)
print("Connection ok with {} from the {} port.".format(host, port))
started = True
while started:
choice = int(input("[1] Send command\n [2] Leave\n > "))
if choice == 1:
command = input(" Command : ")
connexion.send(command.encode())
retour = connexion.recv(1024).decode('latin1')
print(retour)
if choice == 2:
connexion.send("exit")
connexion.close()
break
但是,如果我尝试运行它,则会出现此错误:
Ip :127.0.0.1
Traceback (most recent call last):
File "./test.py", line 6, in <module>
host = input("Ip :")
File "<string>", line 1
127.0.0.1
^
SyntaxError: invalid syntax
我不知道错误在哪里...而且我使用python 3.7来做到这一点。
你能告诉我错误在哪里吗?