【问题标题】:Request entity was not found未找到请求实体
【发布时间】:2020-02-27 05:24:07
【问题描述】:

我正在尝试使用 python 和 firebase 通过令牌向 android 设备发送消息,但是当我运行代码时,我在 response = messaging.send(message) 行出现错误

THIS_FOLDER = os.path.dirname(os.path.abspath(__file__))
my_file = os.path.join(THIS_FOLDER, 'wp-crawler-6265d-firebase-adminsdk-kyj8v-d7ccfaa311.json')

cred = credentials.Certificate(my_file)

 firebase_admin.initialize_app(cred, {
'databaseURL': 'https://wp-crawler-6265d.firebaseio.com/'
})

for i in range(10):
    registration_token = "my key"

    message = messaging.Message(
        android=messaging.AndroidConfig(
            ttl=datetime.timedelta(seconds=3600),
            priority='normal',
            notification=messaging.AndroidNotification(
            title='$GOOG up 1.43% on the day',
            body='$GOOG gained 11.80 points to close at 835.67, up 1.43% on the day.',
        ),
    ),
    token=registration_token,
)
response = messaging.send(message)
print('Successfully sent message:', response)
end = time. time()
print("TIME: ", end-start)

【问题讨论】:

  • 错误提示未找到请求的实体

标签: python firebase firebase-realtime-database firebase-cloud-messaging firebase-admin


【解决方案1】:

看起来正确:您在 for 循环内定义 message,然后尝试在循环外使用它。

如果您想发送 10 条消息,请将 send 调用 移入循环:

for i in range(10):
    registration_token = "my key"

    message = messaging.Message(
        android=messaging.AndroidConfig(
            ttl=datetime.timedelta(seconds=3600),
            priority='normal',
            notification=messaging.AndroidNotification(
                title='$GOOG up 1.43% on the day',
                body='$GOOG gained 11.80 points to close at 835.67, up 1.43% on the day.',
            ),
        ),
        token=registration_token,
    )
    print('Successfully sent message:', response)
    end = time. time()
    print("TIME: ", end-start)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-12-14
    • 2020-02-19
    • 2016-11-06
    • 2021-01-18
    • 1970-01-01
    • 2020-04-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多