import pyrebase
config = {
apiKey: "xxxxxxxxxxxxxxxxx",
authDomain: "lab-marks.firebaseapp.com",
databaseURL: "https://lab-marks.firebaseio.com",
projectId: "lab-marks",
storageBucket: "lab-marks.appspot.com",
messagingSenderId: "9983241061112"
}
firebase=pyrebase.initialize_app(config)
db=firebase.database()
users=db.child('users').get()
print(users.val())
I am integrating python with firebase.But while I run this code I get an NameError, showing that apikey not defined.
apiKey: "xxxxxxxxxxxxxxxxxxxxx",
NameError: name 'apiKey' is not defined
I had the same problem.
You must make the keys in the dictionary config in quotes and then everything will work fine.
P.S: Do not forget to put in quotes and other keys.
For example:
config = {
"apiKey": "xxxxxxxxxxxxxxxxx",
"authDomain": "lab-marks.firebaseapp.com",
"databaseURL": "https://lab-marks.firebaseio.com",
"projectId": "lab-marks",
"storageBucket": "lab-marks.appspot.com",
"messagingSenderId": "9983241061112"
}
Related
When I'm trying to run my code:
import pyrebase
firebaseConfig = {
"apiKey": "xxxxxx",
"authDomain": "xxxxxx",
"projectId": "xxxxxx",
"storageBucket": "xxxxxxx",
"serviceAccount": "xxxxxxxxx"
}
firebase_storage = pyrebase.initialize_app(firebaseConfig)
storage = firebase_storage.storage()
storage.child("uploads").put("xxxxxxx")
I'm getting an error:
self.database_url = config["databaseURL"]
KeyError: 'databaseURL'
I don't know what to do. Can someone help me?
When you create a new Firebase project it no longer creates a Realtime Database by default. And that also means that the databaseURL key is no longer included in the configuration snippet by default.
It looks like Pyrebase still requires this key to exist though, which is why you get an error.
Two things to try (in this order):
Just add a key with no value, or a dummy value to the firebaseConfig:
firebaseConfig = {
"apiKey": "xxxxxx",
"authDomain": "xxxxxx",
"databaseURL": "xxxxxx",
"projectId": "xxxxxx",
"storageBucket": "xxxxxxx",
"serviceAccount": "xxxxxxxxx"
}
If the above doesn't work, you can create a Realtime Database in the Firebase console, and get the new config snippet from there.
I also filed an issue against Pyrebase to no longer require this key, which is what all official Firebase SDKs have been updated to do.
Add
"databaseURL" : ""
in firebaseConfig (if you are not using database).
You need to add databaseURL key to your configurations.
Please take a look at this answer:
KeyError: 'databaseURL' while Firebase Authentication in Python
import pyrebase
config ={
"apiKey": "*********",
"authDomain": "***-****.firebaseapp.com",
"projectId": "****-*****",
"storageBucket": "****-***.appspot.com",
"messagingSenderId": "********",
"appId": "1:********:web:*********",
"measurementId": "G-*********",
"databaseURL" : ""
}
firebase = pyrebase.initialize_app(config)
storage = firebase.storage()
storage.child("download1.png").put("download.png")
Rules
rules_version = '2';
service firebase.storage {
match /b/{bucket}/o {
match /{allPaths=**} {
allow read, write;
}
}
}
I am working on django-rest-framework site and keep getting and error with the index.js file. I've tried adding the .mjs file extension and changing package.json but nothing has fixed this error. VS code gives me the error of 'App is declared but its value is never read ts(6133). I run the python manage.py runserver and then the npm dev server command and I do not have any errors yet I am still not able to get the site to render some of the values in the console properly.
I am new to programming so please forgive my ignorance as I pretend to know something about what I am talking about here.
Here is my index.js file
import App from "./components/App";
This is the App.js file
import React, { Component } from "react";
import { render } from "react-dom";
import HomePage from "./HomePage";
export default class App extends Component {
constructor(props) {
super(props);
}
render() {
return (
<div>
<HomePage />
</div>
);
}
}
const appDiv = document.getElementById("app");
render(<App />, appDiv);
package.json file
{
"name": "frontend",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"dev": "webpack --mode development --watch",
"build": "webpack --mode production"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"#babel/core": "^7.12.10",
"#babel/preset-env": "^7.12.11",
"#babel/preset-react": "^7.12.10",
"babel-loader": "^8.2.2",
"webpack": "^5.11.0",
"webpack-cli": "^4.2.0"
},
"dependencies": {
"#babel/plugin-proposal-class-properties": "^7.12.1",
"#material-ui/core": "^4.11.2",
"#material-ui/icons": "^4.11.2",
"react": "^17.0.1",
"react-dom": "^17.0.1",
"react-router-dom": "^5.2.0"
}
}
Any help is very much appreciated!
That's just a lint. It's telling you that in index.js, you have declared a variable (App), and not used it. Bad programming practice, so your linter (I think VSCode lints JS by default, or maybe you have installed a linter like ESLint) is telling you that. The 6133 number is the error number in the linter.
I would like to set the rules tab of my firebase object to read only.
When I take off the write parcel I got an error on my python when trying to add files to my storage.
Below is my code
import firebase_admin
config={
"apiKey": "xxx",
"authDomain": "xxx",
"databaseURL": "xxx",
"projectId": "xxx",
"storageBucket": "xxx",
"messagingSenderId": "xxx",
"appId": "xxx",
"measurementId": "xxx"
}
# Initialize connection to firebase_admin
firebase = firebase_admin.initialize_app(config)
storage = firebase.storage()
path_on_cloud ="Data quality report/Data quality report.py"
path_local = "Data_quality_report.py"
storage.child(path_on_cloud).put(path_local)
My rules tab is
service firebase.storage {
match /b/{bucket}/o {
match /{allPaths=**} {
allow read;
allow write: if request.auth != null;
}
}
}
Do you guys know how to fix this problem?
Thank you in advance
Don't initialize it that way!
You are using the firebase_admin package which using the Firebase Admin SDK. To initialize it create a new service account key file which is then used for initializing.
Admin does what it sounds like it would do. It has all privileges.
Refer the official docs for proper explanation on setup. (I am really bad at explaining things).
https://firebase.google.com/docs/storage/admin/start#python
I tried creating a Data Transfer Service using bigquery_datatransfer. I used the following python library,
pip install --upgrade google-cloud-bigquery-datatransfer
Used the method
create_transfer_config(parent, transfer_config)
I have defined the transfer_config values for the data_source_id: amazon_s3
transfer_config = {
"destination_dataset_id": "My Dataset",
"display_name": "test_bqdts",
"data_source_id": "amazon_s3",
"params": {
"destination_table_name_template":"destination_table_name",
"data_path": <data_path>,
"access_key_id": args.access_key_id,
"secret_access_key": args.secret_access_key,
"file_format": <>
},
"schedule": "every 10 minutes"
}
But while running the script I'm getting the following error,
ValueError: Protocol message Struct has no "destination_table_name_template" field.
The fields given inside the params are not recognized. Also, I couldn't find what are the fields to be defined inside the "params" struct
What are the fields to be defined inside the "params" of transfer_config to create the Data Transfer job successfully?
As you can see in the documentation, you should try putting your code inside the google.protobuf.json_format.ParseDict() function.
transfer_config = google.protobuf.json_format.ParseDict(
{
"destination_dataset_id": dataset_id,
"display_name": "Your Scheduled Query Name",
"data_source_id": "scheduled_query",
"params": {
"query": query_string,
"destination_table_name_template": "your_table_{run_date}",
"write_disposition": "WRITE_TRUNCATE",
"partitioning_field": "",
},
"schedule": "every 24 hours",
},
bigquery_datatransfer_v1.types.TransferConfig(),
)
Please let me know if it helps you
I'm getting a KeyError while using the JSON library in Python (with Flask)
I don't really understand it.
KeyError: 'sites'
is the error I'm getting
JSON Code:
{
"sites": {
"example-site": {
"domains": [
"example.pagehost.com",
"127.0.0.1:5000"
],
"pages": {
"index/": "index.html"
},
"index": "index.html",
"owner": "Bevan",
"id": "example-site"
}
}
}
Python Code:
global sites_json
fsite = ""
print("Finding site")
for site in sites_json['sites']:
for domain in site['domains']:
if domain == host:
fsite = site
print("Found site")
break
The infringing line appears to be the for site in sites_json['sites']
May someone who knows what is going on please help?
After some messing around, it turns out that I was launching my Flask app through the python3 -m flask run command, which skipped my JSON file's initialisation steps. When I launch through the python3 app.py command, it works correctly!