0

您好,我正在尝试使用 yowsup 发送消息,但我没有成功,您能帮我解决一下 IndentationError: unexpected indent 谢谢

从 yowsup.layers.interface 导入 YowInterfaceLayer,ProtocolEntityCallback 从 yowsup.layers.protocol_messages.protocolentities 导入 TextMessageProtocolEntity 从 yowsup.common.tools 导入 Jid

EchoLayer 类(YowInterfaceLayer):

@ProtocolEntityCallback("message")
def onMessage(self, messageProtocolEntity):

    if messageProtocolEntity.getType() == 'text':
        self.onTextMessage(messageProtocolEntity)

     reply = 1
     messageEntity = TextMessageProtocolEntity(reply,to = messageProtocolEntity.getFrom())

self.toLower(messageEntity)

    self.toLower(messageProtocolEntity.forward(messageProtocolEntity.getFrom()))
    self.toLower(messageProtocolEntity.ack())
    self.toLower(messageProtocolEntity.ack(True))


@ProtocolEntityCallback("receipt")
def onReceipt(self, entity):
    self.toLower(entity.ack())

def onTextMessage(self,messageProtocolEntity):
    # just print info
    print("Echoing %s to %s" % (messageProtocolEntity.getBody(), messageProtocolEntity.getFrom(False)))
4

2 回答 2

0

错误消息将Unexpected indent始终告诉您在哪一行检测到问题。

在您的情况下,这显然是由于ifandreply行不匹配。

于 2017-05-09T19:04:49.943 回答
0

IndentationError:意外缩进

这是每个蟒蛇都遇到过的常见问题。您的代码有一些额外的空间或使用了任何选项卡。所以基本上您必须检查每一行并手动删除多余的间隙(快捷方式)并用插入的空格替换它们。

于 2017-05-09T18:30:39.223 回答