WoolDoughnut310 / micropython-firebase-firestore

Firebase Firestore implementation for Micropython.
MIT License
8 stars 2 forks source link

Urequest.request is not handling urls properly #6

Closed xITmasterx closed 11 months ago

xITmasterx commented 1 year ago

I was supposed to post the changes made for my entry in the database in Firestore, when this error popped up:


{
 "error": {
   "code": 400,
   "message": "Document parent name \"projects/vendo-app-979f8/databases/(default)/documents/products\" lacks \"/\" at index 63.",
   "status": "INVALID_ARGUMENT"
  }
}

I tracked the error down and printed the final path before being sent to Firestore. Here's the code used to send, as well as the link that was being sent using urequest.request:


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 == "POST":
        print(path)
        response = urequests.request(method, path, data=None, json=data)
    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 = json["error"]
            code = error["code"]
            message = error["message"]
            raise FirestoreException(message, code)
        return jsonResponse

And the path printed: https://firestore.googleapis.com/v1/projects/vendo-app-979f8/databases/(default)/documents/products/001

why won't urequest recognize the last part of the url? And is there a fix to it?

Thanks for the help in advance.

rhylkiio commented 1 year ago

Hello were you able to fix the issue and create a document in Firestore successfully? If so please help

HeliNeres commented 11 months ago

Did you fixed this issue?

xITmasterx commented 11 months ago

I have fixed it, though I may have forgotten exactly how I managed to fix it, since its been months since. But it's amounts to adjusting the url, programming, and database structure to make sure that the items are properly queried. Will close this.

HeliNeres commented 11 months ago

Can you explain ou post your updated code?

xITmasterx commented 11 months ago

image Something like this. A bit of adjustment in the url code to ensure that the id of the item is recognized. At least, that's what I remembered.