I'm using the Firebase SDK with Flask to develop an API and I can retrieve records using GET but can't insert records using a PUT/POST into a Firebase collection. The strange thing is that I get no errors or exceptions when executing the code but no records are added to the collection. Here's the code snippet.
cred = credentials.Certificate("serviceAccountKey.json")
firebase_admin.initialize_app(cred)
db=firestore.client()
app = Flask(__name__)
@app.route('/offers',methods = ['PUT'])
def put_offer():
try:
cc_code = db.collection('offers').add({'offer_email': 'foo@foo.com'})
print( "cc code = ", cc_code )
return( '200' )
except Exception as e:
return f"An Error Occured: {e}"
if __name__ == '__main__':
app.run(debug = True)
I created a new python program and called
subprocess.run("python3 ./addoffer.py", shell=True )
this was not a fix but a workaround!
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.