micropython-lib icon indicating copy to clipboard operation
micropython-lib copied to clipboard

Urequest.request is not handling urls properly

Open xITmasterx opened this issue 2 years ago • 1 comments

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.

xITmasterx avatar May 31 '23 10:05 xITmasterx

Hi

What do you mean by "recognize the last part of the url" ?

There isn't the query separator (character ?), so the full URL https://firestore.googleapis.com/v1/projects/vendo-app-979f8/databases/(default)/documents/products/001 is sent AS-IS to the server.

massimosala avatar Jun 28 '23 19:06 massimosala