Firebase Emulators UI doesn't show any data - firebase

I am starting my emulators with:
`firebase emulators:start --project projectId``
Then on a Python script I am doing:
import os
import firebase_admin
from google.cloud import firestore
os.environ['FIRESTORE_EMULATOR_HOST'] = "localhost:8080"
os.environ['GCLOUD_PROJECT'] = "projectId"
fs_root = firestore.Client()
fs_root.collection('data').document('1').set({'key':'value'})
The data is written, I can retrieve it in Python. But if I check my Emulators UI nothing is there.

Related

Build failed: npm ERR! Cannot read property 'firebase-admin' of undefined

I am trying to update a Firebase Cloud Function that I havent touched for a year. Deployment went without issues back then.
Here is my setup: I have a root index.ts file, and functions are organized into folders.
root index.ts
import {initializeApp} from "firebase-admin";
// Initialize Firebase Admin
initializeApp();
export {notifyNewMessages} from "./notify_new_messages";
export {onUpdateUsers, onUpdateUserRatings} from "./on_update/index";
export {onUninstall} from "./on_uninstall/index";
and notifyNewMessages file starts like this
import {FirebaseError, firestore, messaging} from "firebase-admin";
import * as functions from "firebase-functions";
import i18n from "./localization";
import {Ask, Device, User} from "./models";
import DocumentSnapshot = firestore.DocumentSnapshot;
const fcm: messaging.Messaging = messaging();
Could this separated root file cause this problem?
Cheers,
It looks like you are using ES Modules, and as firebase has moved to modular SDK namespace versions require some modifications so try the following:
import * as admin from 'firebase-admin';
const app: admin.app.App = admin.initializeApp();
You can go through this docs for other changes to be made.

How to import firebase storage in web? I got an error everytime I run it. I already got the dependencies in my pubspec

I got it my pubscpec and I import it whenever I used it like this:
import 'package:firebase_storage/firebase_storage.dart';
FirebaseStorage fs = FirebaseStorage.instance;
This is the error I got. I need to upload image

I cannot initialize Flask SocketIO with app.from_object parameter

I have an app.py file where I initialize my app. I have another file (run.py) where I run Flask server from. Everything works with a standard flask app. However I am trying to integrate flask-socketio and it keeps failing with different errors depending on how I try to initialize the app.
I have tried the following ways to initialize flask-socketio:
socketio = SocketIO(app.config.from_object(app_config[env_name]))
socketio = SocketIO(app, **app.config[env_name])
socketio = SocketIO(**app.config[env_name])
Here is the relevant code from my app.py file.
def create_app(env_name):
"""
Create app
"""
# app initiliazation
app = Flask(__name__)
app.config.from_object(app_config[env_name])
async_mode = None
# initializing bcrypt and db
bcrypt.init_app(app)
db.init_app(app)
socketio = SocketIO(app.config.from_object(app_config[env_name]))
return socketio
My run.py file looks like this:
rom src.app import create_app
load_dotenv(find_dotenv())
env_name = os.getenv('FLASK_ENV')
app = create_app(env_name)
if __name__ == '__main__':
port = os.getenv('PORT')
# run app
app.run(app, host='0.0.0.0', port=port)
You will notice I am importing from a config.py file. That is where my environment variables are being for (dev, test, prod). Each environment is it's own class. For example:
class Development(object):
"""
Development environment configuration
"""
DEBUG = True
TESTING = False
SQLALCHEMY_TRACK_MODIFICATIONS=False
JWT_SECRET_KEY = os.getenv('JWT_SECRET_KEY')
SQLALCHEMY_DATABASE_URI = os.getenv('DATABASE_URL')
ALLOWED_EXTENSIONS = set(['png', 'jpg', 'jpeg', 'gif'])
UPLOADED_FILES_DEST = os.getenv('UPLOADED_FILES_DEST')
As you can see, most of those values are set in an environment variable since it is bad practice to put such sensitive information into a repo.
I would like to be able to initialize flask-socketio so I can setup rooms where users can share location based information.
Thanks in advance.
The Flask-SocketIO extensions takes the application instance as an argument. You should configure the application and then initialize it. For example:
app.config.from_object(app_config[env_name])
socketio = SocketIO(app)
I found the issue. I cannot instantiate SocketIO in my app.py file. I have to export app from my app.py file and instantiate SocketIO in my run.py file. My final code looks like this:
app.py
def create_app(env_name):
"""
Create app
"""
# app initiliazation
app = Flask(__name__)
app.config.from_object(app_config[env_name])
# initializing bcrypt and db
bcrypt.init_app(app)
db.init_app(app)
return app
Finally, my run.py file looks like this.
import os
import logging
from dotenv import load_dotenv, find_dotenv
from flask_socketio import SocketIO, join_room, emit
from src.app import create_app
load_dotenv(find_dotenv())
env_name = os.getenv('FLASK_ENV')
app = create_app(env_name)
socketio = SocketIO(app)
if __name__ == '__main__':
port = os.getenv('PORT')
# run app
socketio.run(app, host='0.0.0.0', port=port)

No such module PushNotifications (Swift 4 + Xcode 9.0) Firebase

Use Xcode9, Swift4 no work on real Iphone6
Two issues:
Redefinition of Module 'Firebase'
No such module 'UserNotifications'
but if I use Simulator all is good!
install firebase pod and import following modules
import Firebase
import FirebaseMessaging
import UserNotifications

SQLAlchemy extension isn't registered when running app with Gunicorn

I have an application that works in development, but when I try to run it with Gunicorn it gives an error that the "sqlalchemy extension was not registered". From what I've read it seems that I need to call app.app_context() somewhere, but I'm not sure where. How do I fix this error?
# run in development, works
python server.py
# try to run with gunicorn, fails
gunicorn --bind localhost:8000 server:app
AssertionError: The sqlalchemy extension was not registered to the current application. Please make sure to call init_app() first.
server.py:
from flask.ext.security import Security
from database import db
from application import app
from models import Studio, user_datastore
security = Security(app, user_datastore)
if __name__ == '__main__':
# with app.app_context(): ??
db.init_app(app)
app.run()
application.py:
from flask import Flask
app = Flask(__name__)
app.config.from_object('config.ProductionConfig')
database.py:
from flask.ext.sqlalchemy import SQLAlchemy
db = SQLAlchemy()
Only when you start your app with python sever.py is the if __name__ == '__main__': block hit, where you're registering your database with your app.
You'll need to move that line, db.init_app(app), outside that block.

Resources