我在 Google Hangouts Chat 的聊天室中设置了 webhook。
我可以成功运行他们的示例代码,它会从与聊天中的 webhook 关联的机器人生成一条消息:
from httplib2 import Http
from json import dumps
#
# Hangouts Chat incoming webhook quickstart
#
def main():
url = '<INCOMING-WEBHOOK-URL>'
bot_message = {
'text' : 'Hello World!'}
message_headers = { 'Content-Type': 'application/json; charset=UTF-8'}
http_obj = Http()
response = http_obj.request(
uri=url,
method='POST',
headers=message_headers,
body=dumps(bot_message),
)
print(response)
if __name__ == '__main__':
main()
但是当我尝试使用代码发送一个 Numpy 数组时:
bot_message = {
'text' : NumpyArrayObject}
我得到错误:
TypeError: Object of type 'ndarray' is not JSON serializable
使用 Python list 我得到了错误:
"description": "Invalid JSON payload received. Unknown name \\"text\\" at \'message\': Proto field is not repeating, cannot start list."\n }\n ]\n }\n ]\n }\n}\n')
我应该怎么办?