【发布时间】:2021-01-11 17:30:38
【问题描述】:
为什么我从谷歌复制了正确的代码后出现此错误如何解决此错误。
import socket
import threading
bind_ip = "0.0.0.0"
bind_port = 9999
server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server.bind((bind_ip, bind_port))
server.listen(5)
print("[-#-] Listening on %s:%d" % (bind_port, bind_ip))
# this is our clint-hanadaling thread
def handle_client(client_socket):
# print out what client sends
request = client_socket.recv(1024)
print("[* ] Received %s " % request)
# send back a request
client_socket.send("ACK!")
client_socket.close()
while True:
client, addr = server.accept()
print("[*] Accepted connection from %s:%d" % (addr[0], addr[1]))
# spin up our client thread to handle incoming data
clinet_handler = threading.Thread(target=handle_client, args=client)
clinet_handler.start()
在以下位置出现错误:Traceback(最近一次调用最后一次):文件 “c:/Users/Najuser/Desktop/PYThon/tcp.py”,第 10 行,在 print("[-#-] Listening on %s:%d" % (bind_port, bind_ip)) TypeError: %d format: a number is required, not str
【问题讨论】:
标签: python python-3.x ip string-formatting