import socket import traceback import sys host = '172.22.102.20' port = 51423 s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) s.bind((host, port)) s.listen(1) ClientSock, ClientAddr = s.accept() while 1: try: buf = ClientSock.recv(1024) if len(buf): print("he say: " + buf.decode()) data = input("I say: ").encode() ClientSock.sendall(data) except: print("Dialogue Over") ClientSock.close() sys.exit(0)这个代码有 File "C:\Users\Administrator\PycharmProjects\chat\serve.py", line 18 if len(buf): ^ IndentationError: unexpected indent
时间: 2023-12-12 11:03:20 浏览: 33
这个错误是因为 if 语句下面的代码缩进不正确。你需要检查一下代码中的缩进是否正确,建议使用 4 个空格来缩进代码。以下是修复后的代码:
```
import socket
import traceback
import sys
host = '172.22.102.20'
port = 51423
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
s.bind((host, port))
s.listen(1)
ClientSock, ClientAddr = s.accept()
while 1:
try:
buf = ClientSock.recv(1024)
if len(buf):
print("he say: " + buf.decode())
data = input("I say: ").encode()
ClientSock.sendall(data)
except:
print("Dialogue Over")
ClientSock.close()
sys.exit(0)
```
相关问题
self._traceback = tf_stack.extract_stack()
这段代码的意思是将当前的调用堆栈信息存储在`self._traceback`中。`tf_stack.extract_stack()`是TensorFlow中的一个函数,用于提取当前的调用堆栈信息。通过将堆栈信息保存在`self._traceback`中,可以方便地在程序出现错误时进行调试和排查问题。
in import_optional_dependency module = importlib.import_module(name)
As an AI language model, I cannot provide a specific answer without more context. Can you please provide more information about the specific code snippet and any error messages or traceback information that you are seeing? This will help me better understand the issue and provide a more accurate response.