Python 尝试使用请求将数据发布到firestore

Python 尝试使用请求将数据发布到firestore,python,google-cloud-firestore,python-requests,Python,Google Cloud Firestore,Python Requests,我试图使用请求将JSON数据发布到firestore,firestore不断返回此错误 { "error": { "code": 400, "message": "Invalid JSON payload received. Unknown name \"{\"data\": \"message\"}\": Cannot bind query parameter. Field '{\"data\": \"message\"}' could not be found in re

我试图使用请求将JSON数据发布到firestore,firestore不断返回此错误

{
  "error": {
    "code": 400,
    "message": "Invalid JSON payload received. Unknown name \"{\"data\": \"message\"}\": Cannot bind query parameter. Field '{\"data\": \"message\"}' could not be found in request message.",
    "status": "INVALID_ARGUMENT",
    "details": [
      {
        "@type": "type.googleapis.com/google.rpc.BadRequest",
        "fieldViolations": [
          {
            "description": "Invalid JSON payload received. Unknown name \"{\"data\": \"message\"}\": Cannot bind query parameter. Field '{\"data\": \"message\"}' could not be found in request message."
          }
        ]
      }
    ]
  }
}

我尝试过使用不同类型的JSON编码的不同方法,但仍然返回相同的错误。如果有人能帮我调查一下,我将不胜感激。下面是我的代码

    def thestream(self, instance):
        app = App.get_running_app()
        s = requests.Session()
        self.data = {u'data': u'message'}
        self.headers = {"authorization": "bearer " + app.idToken}
        r = s.post("https://firestore.googleapis.com/v1/projects/*******************************/databases/(default)/documents/messages/TemitayoAdefemi", params=json.dumps(self.data), headers=self.headers)
        print(r.ok)
        print(r.content.decode())

尝试在有效负载中定义一个:

self.data = {u'fields': {u'data': {u"stringValue": u'message'}}}
在POST请求中,尝试以
data=self.data
而不是
param
传递有效负载:

r = s.post("https://firestore.googleapis.com/v1/projects/***/databases/(default)/documents/messages/TemitayoAdefemi", data=self.data, headers=self.headers)

谢谢您,但收到了此错误
False{“error”:{“code”:400,“message”:“接收到无效的JSON负载。意外的令牌。\n字段=数据\n^”,“status”:“Invalid_ARGUMENT”}
我相信这是因为
param
在URL中传递数据。试着在你的POST请求中使用
data=self.data
。很好!请共享修复以帮助其他人:-)