我在python中有这段代码 whoose 的目的是通过 websocket 发送一个文本文件 .c .txt(无论如何,我一直在发送一个 helloworld.c)。
问题是当我测试它时,代码没有超出print("I'm here!")
def onMessage_function(self, client_id, message):
print("Here's the message I received " + message + "nnn")
dumpedMSG = json.dumps(message)
loadedMSG = json.loads(dumpedMSG)
if 'file_name' in loadedMSG:
print("I'm here!")
print(loadedMSG['file_name'])
else:
# do something else here.
谢谢!
很难说,但这行得通吗?
def onMessage_function(self, client_id, message):
print("Here's the message I received " + message + "nnn")
loadedMSG = json.loads(message)
if 'file_name' in loadedMSG:
print("I'm here!")
print(loadedMSG['file_name'])
else:
# do something else here.
在原始loadedMSG
中将与message
相同,因此'file_name' in loadedMSG
将是子字符串检查而不是字典键的检查。然后,"我在这里!"之后的打印将引发异常,如果您只接收通过套接字发送的内容,则可能看不到该异常。