Skip to content

I can read but not create #1

@JMFUZ

Description

@JMFUZ

Hi,
I'm trying this library and fth firebase-firestore one.
I can connect to my database because I can read
But I can't write in it and I've no error message, then I can't know why

Firestore rules :

rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
match /users/{user} {
allow read, write: if request.auth != null;
}
}
}

My code :

import os
import network
import time
import ujson, urequests, _thread

SSID = "SSID"
password = "password"
wlan = network.WLAN(network.STA_IF)
wlan.active(True)

if not wlan.isconnected():
wlan.connect(SSID, password)
print("Attente de la connexion WIFI", end="...")
while not wlan.isconnected():
print(".", end="")
time.sleep(1)
print()

print("Reseau WIFI", SSID , "connecté :", wlan.ifconfig()[0])

import ufirestore as firestore
from json import FirebaseJson
from firebase_auth import FirebaseAuth
from firebase_auth import AuthSession

firestore.set_project_id("firestore-db-test1")

auth = FirebaseAuth("API_KEY")
auth.sign_in("mail@gmail.com", "AAAAAAA")

firestore.set_access_token(auth.session.access_token)

print("===== Lecture =====")
print("")
raw_doc = firestore.get("users/")
print("raw_doc : ", raw_doc)
print("")

print("===== Ecriture =====")
print("")
doc = FirebaseJson()
doc.set("Name/stringValue", "John Doe")
doc.set("Age/integerValue", 25)

response = firestore.create("users/", doc, bg=False)
print(response)

auth.sign_out()

The results :

===== Lecture =====

raw_doc : {'documents': [{'fields': {'Age': {'stringValue': '21'}, 'Name': {'stringValue': 'Jane Doe'}}, 'createTime': '2022-10-31T12:32:34.756017Z', 'name': 'projects/firestore-db-test1/databases/(default)/documents/users/FhjDBdURqcaQlpwdXlFG', 'updateTime': '2022-10-31T12:32:34.756017Z'}]}

===== Ecriture =====

Traceback (most recent call last):
File "", line 92, in
File "ufirestore.py", line 222, in create
File "ufirestore.py", line 90, in create
File "ufirestore.py", line 53, in send_request
File "urequests.py", line 104, in request
AssertionError:

I need help because I really don't know I happened

Thanks in advance

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions