我在python中使用pyrebase库作为我的脚本。
def expand_companies(self, db, company_type):
url_companies = "https://api-imdb.com/companies/%d"
all_movies = db.child("movies/data").get()
for pyre_movie in all_movies .each():
movie= pyre_movie.val()
if company_type in pyre_movie :
for company_id in movie[company_type]:
print(url_companies % company_id)
if db.child("companies/data").order_by_child("id").equal_to(company_id).limit_to_first(1).get() is None:
request_company = requests.get(url_companies % company_id, headers=self.headers)
if request_company.status_code == 200:
company_json_object = request_company.json()
if company_json_object:
company_object = company_json_object[0]
print(company_object)
db.child("companies/data").push({'id': company_id, 'name': company_object['name'], 'type': company_type.rstrip('s')})
以下这一行:
if db.child("companies/data").order_by_child("id").equal_to(company_id).limit_to_first(1).get() is None:
导致以下错误:
requests.exceptions.HTTPError:[Errno 400客户端错误:网址错误请求:https://my_database.firebaseio.com/companies/data.json?orderBy=%2522id%2522&equalTo=2527&limitToFirst=1] { "错误" :"索引未定义,添加\" .indexOn \":\" id \",路径\" / companies / data \&#34 ;,遵守规则"
奇怪的部分是我的firebase数据库的每个其他查询,无论是push,delete还是set都没有返回错误,并成功完成查询而没有任何错误。我知道我已成功连接到我的数据库。请帮我修复此错误。