马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
如题,在使用pushdeer的时候,发现了如下的问题,先附上代码:import os
from dotenv import load_dotenv
from pypushdeer import PushDeer
from datetime import datetime
import json
import requests
# 加载 .env 文件
load_dotenv()
# 读取配置文件
with open("config.json", "r", encoding="utf-8") as f:
config = json.load(f)
def httpGet(url, params):
try:
response = requests.get(url, params=params)
response.raise_for_status() # 检查请求是否成功
return json.loads(response.content) # 返回 JSON 解析后的内容
except requests.exceptions.RequestException as e:
print(f"GET 请求失败: {e}")
return {"success": False, "message": str(e)}
except json.JSONDecodeError as e:
print(f"JSON 解析失败: {e}")
return {"success": False, "message": str(e)}
# 获取抖音热点热榜
def getDouyinHot():
url = "https://api.vvhan.com/api/hotlist/douyinHot"
response = httpGet(url, {"type": "json"})
if response.get("success"):
data = response.get("data")
douyinHotList = []
douyinHot = ""
for item in data:
index = item["index"]
title = item["title"]
url = item["mobil_url"]
douyinHotListItem = f"{index}. [{title}]({url})"
douyinHotList.append(douyinHotListItem)
douyinHot = "\n".join(douyinHotList)
return douyinHot
else:
print("抖音热榜获取失败")
return ""
# 获取服务器地址和 pushkeys
server = os.getenv("SERVER")
gaoDeKey = os.getenv("GAODE_KEY")
# pushkeys = os.getenv("PUSHKEYS", "").split(",")
pushkey = os.getenv("PUSH_KEY")
# 获取对应方法返回的数据
today = datetime.now().strftime("%Y年%m月%d日")
douyinHotList = getDouyinHot()
def main():
print(type(douyinHotList))
print(douyinHotList)
global pushkey # 声明使用全局变量
pushkey = pushkey.strip() # 去除可能存在的前后空格
# 初始化 PushDeer 对象
pushdeer = PushDeer(server=server, pushkey=pushkey)
# 发送消息
try:
response = pushdeer.send_markdown(f"{today}抖音热榜", desp=douyinHotList)
print("消息发送成功:", response)
except Exception as e:
print("消息发送失败:", e)
if __name__ == "__main__":
main()
运行之后,douyinHotList打印出来是没问题的,有东西,类型也是str,就是发送的这一句,response = pushdeer.send_markdown(f"{today}抖音热榜", desp=douyinHotList)报错,消息发送失败: Expecting value: line 1 column 1 (char 0)
之前用这个pushdeer.send_markdown一点问题都没有,直接发送markdown的图片和链接都可以,这次不知道为什么,大佬帮忙看看 |