2017-01-03 18 views
0

我試圖使用Udacity reviewer API排隊等待被分配的項目。但是,我無法弄清楚如何使用/submission_requests POST調用。現在,我在Python這樣做:如何等待與Python中的Udacity審閱者API一致?

import requests 

TOKEN = os.getenv('udacity_api_key') 
BASE_URL = 'https://review-api.udacity.com/api/v1/' 
headers = {'Authorization': TOKEN} 
req_url = BASE_URL + 'submission_requests' 
proj_req_data = { 
    "projects": [ 
    { 
     "project_id": 232, 
     "language": "en-us" 
    } 
    ] 
} 
res = requests.post(req_url, headers=headers, data=proj_req_data) 

和響應(print res.content)是:

{"error":"request must have at least one valid project/language pair"} 

我也試過成 'en' 作爲語言。我從/me/certifications獲得了project_id GET方法。

回答

0

原來我用的requests.post()函數錯誤的參數。如果數據作爲字典傳遞,則需要在json arg中。如果它在data參數中,則需要將其與json.dumps()串聯起來。

這裏有一個很好的Python API代碼示例:https://github.com/udacity/grading-assigner

相關問題