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': {}}
SPFort
  • 53
  • 1
  • 10
  • Without *reading the docs* (pointer) I'm wondering about the `$`. It doesn't look right. – Klaus D. Mar 30 '18 at 15:30
  • Before the rest api key? It's in the rest api docs provided by back4app. I tried removing it and nothing seems to change, same result. – SPFort Mar 30 '18 at 15:37

3 Answers3

0

I'm really recommend to use requests package. The package is very nice, for HTTP calls.

Little example for the your case.

# Your payloads
params = {
    "X-Parse-Application-Id": "app-id",
    "X-Parse-REST-API-Key": "YOUR_IP_KEY"
}


url = 'https://parseapi.back4app.com/parse/classes/Congressmen'


# GET method, with URI parameters
response = requests.get(url, params=params)

print(response.url)

# Get json data from a response.
print(response.json())
  • I still have the same problem. The response I get is: {'error': 'unauthorized'} – SPFort Mar 30 '18 at 15:53
  • `{'error': 'unauthorized'} ` meant that you provided an bad credentials, check your `app-id` or `api_key`. –  Mar 30 '18 at 16:18
  • My app-id and Rest-Api-key are definitely correct, I have quadruple checked them at this point. The thing I am most unsure about is honestly the url I am using. Am I using the correct url? If not, where do I find the correct one? – SPFort Mar 30 '18 at 16:38
  • I don't know anything about `parseapi` –  Mar 30 '18 at 18:16
0

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,
   })
SPFort
  • 53
  • 1
  • 10
0

To connect to back4app using python requests module, you need to define App ID and REST API Key in headers (not using params)

# Your payloads
headers = {
    "X-Parse-Application-Id": "app-id",
    "X-Parse-REST-API-Key": "YOUR_IP_KEY"
}


url = 'https://parseapi.back4app.com/parse/classes/Congressmen'


# GET method, with URI parameters
response = requests.get(url, headers=headers)

print(response.url)

# Get json data from a response.
print(response.json())
MartinV
  • 1
  • 1