Kivy-尝试将Firebase与我的Kivy应用程序集成吗?杰森错误

时间:2019-02-06 15:47:58

标签: python json firebase python-requests kivy

我观看了一些视频,内容是如何使用带有kivy和python的Firebase数据库通过我的应用程序实现它。但是,我不断得到 raise JSONDecodeError("Expecting value", s, err.value) from None json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)错误。请让我知道是否需要更多代码或信息。

这是我的代码:

class MetropolisApp(App):
database_url = ''
user_num = 1

def build(self):
    return ControlScreens()

def on_start(self):
    # Get database data
    db = requests.get('' + str(self.user_num) + '.json')
    print(db.ok)
    data = json.loads(db.content.decode())
    print(data)

def patch(self, firstname, lastname, phonenumber, username, password):
    user_fname = json.loads(firstname)
    user_lname = json.loads(lastname)
    user_phone = json.loads(phonenumber)
    user_user = json.loads(username)
    user_pw = json.loads(password)
    requests.patch(url=self.database_url, json=user_fname)
    requests.patch(url=self.database_url, json=user_lname)
    requests.patch(url=self.database_url, json=user_phone)
    requests.patch(url=self.database_url, json=user_user)
    requests.patch(url=self.database_url, json=user_pw)

1 个答案:

答案 0 :(得分:0)

您的问题是import { Component, OnInit, ViewChild, ComponentFactoryResolver, NgModule, Compiler, ViewContainerRef } from '@angular/core'; import { ContentDirective } from './../../directives/content.directive'; import { HttpClient } from '@angular/common/http'; import { ComponentsModule } from '@components/components.module'; @Component({ selector: 'app-chapter', templateUrl: './chapter.component.html', styleUrls: ['./chapter.component.scss'] }) export class ChapterComponent implements OnInit { @ViewChild('container', { read: ViewContainerRef }) container: ViewContainerRef; constructor(private resolver: ComponentFactoryResolver, private http: HttpClient, private compiler: Compiler) { } ngOnInit() { this.loadComponent(); } private addComponent(template: string, properties: any = {}) { @Component({ template }) class TemplateComponent { } @NgModule({ declarations: [TemplateComponent], imports: [ComponentsModule] }) class TemplateModule { } const mod = this.compiler.compileModuleAndAllComponentsSync(TemplateModule); const factory = mod.componentFactories.find((comp) => comp.componentType === TemplateComponent ); const component = this.container.createComponent(factory); Object.assign(component.instance, properties); } loadComponent() { // let componentFactory = this.componentFactoryResolver.resolveComponentFactory(adItem.component); const html = this.http.get('/assets/content/chapter1.html', { responseType: 'text' }); html.subscribe( (res) => { this.addComponent(res); }, (err) => console.log(err), () => console.log('Complete') ); } } 是要将json.loads这样的字符串转换成'{"some_key": "some_value"}'这样的python字典。您正尝试在{"some_key": "some_value"}之类的字符串上使用json.loads,这会产生错误。

您想做的(我认为)是这样的:

'Test'

def patch(self, firstname, lastname, phonenumber, username, password): fname_data = {"fname": firstname} # Make a python dictionary requests.patch(url=self.database_url, json=fname_data) # Send the python dictionary 的{​​{1}}关键字参数需要一个python字典。