pythonpython-3.xback4app

How can I retrieve objects from back4app using python 3?


I am trying to interact with a database stored in back4app using python. After sending my GET request, I get "{'message': 'Not Found', 'error': {}}". My python code is as follows:

import json, http.client, urllib.parse
# create a connection to the server
url = "parseapi.back4app.com"
connection = http.client.HTTPSConnection(url)
connection.connect()

# define parameter for GET request
params = urllib.parse.urlencode({"where":json.dumps({"Name": "Dru Love"})})

# perform GET request
connection.request('GET', '/parse/classes/PGA?%s' % params, '', {
       "X-Parse-Application-Id": "app_id",
       "X-Parse-REST-API-Key": "api_key"
     })

# store response in result variable
result = json.loads(connection.getresponse().read())
connection.close()
print(result)

Response:

{'message': 'Not Found', 'error': {}}

Solution

  • The problem is in the call to connection.request(). The "/parse" should be removed from the url that gets passed in. The working code looks as follows:

    connection.request('GET', '/classes/PGA?%s' % params, '', {
           "X-Parse-Application-Id": app_id,
           "X-Parse-REST-API-Key": api_key,
       })