这里需要使用到webhook机器人
创建机器人
示例代码:
import time
import os
import requests
import glob
import csv
# 飞书 webhook 地址
WEBHOOK_URL = "" # 替换为您的飞书群聊 Webhook URL
def send_message_to_lark(message):
"""发送消息到飞书群聊"""
payload = {
"msg_type": "text",
"content": {
"text": message
}
}
headers = {
"Content-Type": "application/json"
}
response = requests.post(WEBHOOK_URL, json=payload, headers=headers)
if response.status_code == 200:
print("消息发送成功")
else:
print(f"发送失败: {response.status_code}, 内容: {response.text}")
for i in range(0,10):
message='这是一个测试文件'
send_message_to_lark(message)
注意:
如果mac端遇到
import requests
ModuleNotFoundError: No module named 'requests'
pip3 install时又遇到了 externally-managed-environment的爆错
如果是通过homebrew安装的python3的话
尝试进入
/opt/homebrew/Frameworks/Python.framework/Versions/Current/lib/python3.13
执行rm -f EXTERNALLY-MANAGED
重新执行 pip3 install requests
参考:https://blog.youkuaiyun.com/weixin_74305707/article/details/143748718