换行符在 pymsteams 文本中不起作用

New line characters not working in pymsteams text

提问人:Komal 提问时间:10/11/2023 最后编辑:Arnab NandyKomal 更新时间:10/12/2023 访问量:46

问:

我从 Linux 机器上获得了以下输出,我正在尝试将其推送到 MS Teams 频道。但是,当文本显示在团队频道中时,输出格式会发生变化。换行符不起作用。

stdin, stdout, stderr = client.exec_command("ip addr | grep bond0")
pwd_out=stdout.read().decode("utf-8")
new_text="Link Status:"+"\n" +  pwd_out
print(new_text)
myTeamsMessage.text(new_text)

Python 终端输出:

`> Link Status:
6: ens1f0: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 1500 qdisc mq master bond0 state UP group default qlen 1000
9: ens2f1: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 1500 qdisc mq master bond0 state UP group default qlen 1000
10: bond0: <BROADCAST,MULTICAST,MASTER,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
11: bond0.400@bond0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
    inet 192.168.40.10/24 brd 192.168.40.255 scope global noprefixroute bond0.400
12: bond0.501@bond0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
    inet 192.168.51.16/24 brd 192.168.51.255 scope global noprefixroute bond0.501`

MSTEAMS输出:

payload: {'text': 'Link Status:\n6: ens1f0: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 1500 qdisc mq master bond0 state UP group default qlen 1000\n9: ens2f1: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 1500 qdisc mq master bond0 state UP group default qlen 1000\n10: bond0: <BROADCAST,MULTICAST,MASTER,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000\n11: bond0.400@bond0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000\n    inet 192.168.40.10/24 brd 192.168.40.255 scope global noprefixroute bond0.400\n12: bond0.501@bond0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000\n    inet 192.168.51.16/24 brd 192.168.51.255 scope global noprefixroute bond0.501\n'}

有没有办法让 MS 团队的输出与 Python 终端输出相同?

python linux 文本 microsoft-teams 换行符

评论

0赞 JonSG 10/11/2023
你试过吗new_text="Link Status:"+"\r\n" + pwd_out
0赞 Meghana-MSFT 10/12/2023
请尝试使用上面 JonSG 提到的 \r\n。
0赞 Komal 10/12/2023
“链接状态:”+“\r\n” + pwd_out不起作用
0赞 Meghana-MSFT 10/13/2023
使用以下任何一种,它都会给出相同的输出 - new_text=“链接状态:”+“\n\r” + “test123”, new_text=“链接状态:”+“\r\r” + “test123”, new_text=“链接状态:”+“\n\n” + “test123” - i.stack.imgur.com/rx8s5.png

答: 暂无答案