在Raspberry pi picow

问题描述 投票:0回答:1
eRROR消息:

Traceback (most recent call last): File "<stdin>", line 50, in <module> File "/lib/ufirestore/ufirestore.py", line 212, in patch File "/lib/ufirestore/ufirestore.py", line 75, in patch File "/lib/ufirestore/ufirestore.py", line 51, in send_request File "urequests.py", line 104, in request AssertionError:

我尝试了许多方法来解决问题,例如更改“ doc2.set()”和firestore.patch()
的内部。
    

这与云的Firestore API有关,不再与Ufirestore.py.py.

中的内容保持一致。
当前的补丁API在这里,例如:

https://firebase.google.com/docs/firestore/reference/rest/v1beta1/projects.databases.documents.documents/patch
google-cloud-firestore micropython raspberry-pi-pico
1个回答
0
投票

修复您可以在ufirestore.py

中实现 基于此,您可以将以下内容应用于ufirestore.py的更改以实现这一目标:

def send_request(path, method="GET", params=dict(), data=None, dump=True): headers = {} if FIREBASE_GLOBAL_VAR.ACCESS_TOKEN: headers["Authorization"] = "Bearer " + FIREBASE_GLOBAL_VAR.ACCESS_TOKEN if method in ["POST", "PATCH", "PUT"]: # headers["Accept"] = "application/json" # headers["Content-Type"] = "application/json" response = urequests.request(method, path, data=None, json=data, headers=headers) else: response = urequests.request(method, path, headers=headers) if dump == True: if response.status_code < 200 or response.status_code > 299: print(response.text) raise FirestoreException(response.reason, response.status_code) jsonResponse = response.json() if jsonResponse.get("error"): error = jsonResponse["error"] code = error["code"] message = error["message"] raise FirestoreException(message, code) return jsonResponse class INTERNAL: def patch(DOCUMENT_PATH, DOC, cb, update_mask=None): PATH = construct_url(DOCUMENT_PATH) LOCAL_PARAMS = to_url_params() + "&".join([f"updateMask.fieldPaths={field}" for field in update_mask]) DATA = DOC.process() # name in here has been deprecated I believe # https://firebase.google.com/docs/firestore/reference/rest/v1beta1/projects.databases.documents/patch # name is added as a part of the path # updateMask is a query parameter LOCAL_OUTPUT = send_request(PATH+LOCAL_PARAMS, "PATCH", data=DATA) if cb: try: return cb(LOCAL_OUTPUT) except: raise OSError( "Callback function could not be executed. Try the function without ufirestore.py callback.") return LOCAL_OUTPUT def create(COLLECTION_PATH, DOC, cb, document_id=None): PATH = construct_url(COLLECTION_PATH) PARAMS = {"documentId": document_id} if document_id is not None: LOCAL_PARAMS = to_url_params(PARAMS) else: LOCAL_PARAMS = "" # DATA = DOC.process(get_resource_name(PATH)) DATA = DOC.process() LOCAL_OUTPUT = send_request(PATH+LOCAL_PARAMS, "POST", PARAMS, DATA) if cb: try: return cb(LOCAL_OUTPUT) except: raise OSError( "Callback function could not be executed. Try the function without ufirestore.py callback.") return LOCAL_OUTPUT

thisthis假设您正在使用Https://github.com/wooldoughnut310/micropopython-firebase-firestore(或

Https://pypi.org/propropyth/micropopython-firethon-firethon-firestore-firestore-firestore/thin-

由于我遇到了同样的问题,这些是我应用的修复程序(在ESP32上最初写)

NBjson.py更新与ufirestore.pyteweaking

一起进行

注意,还必须更改用ufirestore.py打包的json.py文件以定义firbasejson(...)。process(...)。不进行参数,因为此信息不再在此处通过API调用。 。这看起来如下:
    def process(
        self,
        # name,
    ):
        return {
            # "name": name,
            "fields": self.data
        }

当您进行创建呼叫时,这也将DocumentID作为URL参数,而不是JSON数据的一部分,但是如果剩余空白仍然会为您创建一个,也可以在此处找到:如何设置DOC ID带有firebase RestAPI

即可使用Urequests

提出休息请求

以下是如何直接根据上述Google文档使用API的(使用send_request实用程序,因为它连接您从firebase_auth库中获得的auth标题)

res = ufirestore.send_request( f"https://firestore.googleapis.com/v1/projects/{PROJECT_NAME}/databases/(default)/documents/devices/{DOCUMENT_ID}?updateMask.fieldPaths=watchdog&updateMask.fieldPaths=deviceTemp", method="PATCH", data={ "fields": { "watchdog": {"integerValue": watchdog}, "deviceTemp": {"doubleValue": 24.56}, "displayName": {"stringValue": "hello"}, } }, )

但是,如您所见,某些参数已移动到URL中的查询参数,其他参数仍保留JSON数据(在补丁方法中,请求修补程序的REST请求,而不是由库当前配置的)
您还可以在Google网站上使用REST API(它将为您处理auth)并直接使用UreQuest来构建其余请求(它将与上述请求相似,但是您需要添加按照send_request函数)

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.