2

I'm using Pyrebase to access my Firebase database. My database is currently structured like so:

- users
    - 12345
        name: "Kevin"
        company: "Nike"

Where 12345 is the user's id, and the company is the company that the user belongs to. I'm currently trying to get all the users that belong to Nike. According to the Pyrebase docs, doing something like this should work:

db.child("users").order_by_child("company").equal_to("Nike").get().val()

but I'm getting the error "error" : "orderBy must be a valid JSON encoded path". Does anyone know why this might be the case?

  • Remove the `.val()` at the end. – stovfl Mar 02 '19 at 09:40
  • @stovfl just tried it -- still doesn't work. i think it has something to do with the `order_by_child` cause it's saying that its a bad request. –  Mar 02 '19 at 19:19

2 Answers2

3

There is something wrong with the Pyrebase library. Here's a link to the problem.

The solution is to add these lines of code in your app.

# Temporarily replace quote function
def noquote(s):
    return s
pyrebase.pyrebase.quote = noquote
1

I managed to fix this problem, since I'm also using rest api to connect with my firebase realtime database. I'll demonstrate where the error lies with examples:

When I don't put wrap the orderBy value (child, key, etc) and other queries parameters with commas, retrofit (which I'm using) gives me error/bad request.

Here's the error/bad request url:

https://yourfirebaseprojecturl.com/Users.json?orderBy=username&startAt=lifeofkevin

See, both the orderBy value and startAt value, in this case, username and lifeofkevin, are not wrapped with commas, like this "username" and "lifeofkevin", so it will return orderBy must be a valid JSON encoded path.

In order to work, I need to wrap my orderBy and other query parameters, with commas, so that Firebase returns the data, you want to work with.

Here's the second example, the correct one:

https://yourfirebaseprojecturl.com/Users.json?orderBy="username"&startAt="gang"

Now notice, the difference? Both values of orderBy and startAt are wrapped with commas so now they'll return the data you want to work with.

William Baker Morrison
  • 1,642
  • 4
  • 21
  • 33