2012-07-11 54 views
3

當我要在parse.com的用戶表中發佈用戶數據時,我收到錯誤的請求錯誤。這段代碼有什麼問題?任何幫助Plz。這裏是我的代碼用戶註冊爲'https://api.parse.com/1/users'給出錯誤請求錯誤

if form.is_valid(): # All validation rules pass 
     username = form.cleaned_data['username'] 
     name = form.cleaned_data['name'] 
     password1 = form.cleaned_data['password1'] 
     password2 = form.cleaned_data['password2'] 
     email = form.cleaned_data['email'] 
     data = {"username": username, "name": name, "password": password1, "email": email} 
     data = urllib.urlencode(data) 
     url = settings.API_USER_ROOT 
     http_verb = 'POST' 
     request = urllib2.Request(url, data) 
     request.add_header('Content-type', 'application/json') 
     auth_header = "Basic %s" % base64.b64encode('%s:%s' % (settings.APPLICATION_ID, settings.MASTER_KEY)) 
     request.add_header("Authorization", auth_header) 
     request.get_method = lambda: http_verb 
     try: 
      print '***************' 
      response = urllib2.urlopen(request) 
      print '***********' 
     except urllib2.URLError, e: 
      print e.reason 

回答

0

進口httplib的,JSON

connection = httplib.HTTPSConnection('api.parse.com', 443) 
connection.connect() 
connection.request('POST', '/1/users', json.dumps({ 
    "username": "cooldude6", 
    "password": "p_n7!-e8", 
    "phone": "415-392-0202" 
}), { 
    "X-Parse-Application-Id": "APP ID", 
    "X-Parse-REST-API-Key": "MASTER KEY", 
    "Content-Type": "application/json" 
}) 
result = json.loads(connection.getresponse().read()) 

爲了在HTTPS使用端口443

後發佈