2

我正在尝试使用 python 与存储在 back4app 中的数据库进行交互。发送我的 GET 请求后,我收到“{'message': 'Not Found', 'error': {}}”。我的python代码如下:

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)

回复:

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

2 回答 2

0

我真的建议使用requests包。包裹非常好,适合HTTP打电话。

您的案例的小例子。

# 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())
于 2018-03-30T15:37:01.960 回答
0

问题在于对 connection.request() 的调用。应该从传入的 url 中删除“/parse”。工作代码如下所示:

connection.request('GET', '/classes/PGA?%s' % params, '', {
       "X-Parse-Application-Id": app_id,
       "X-Parse-REST-API-Key": api_key,
   })
于 2018-05-10T18:53:34.977 回答