By emmerich
on Thu, 01/09/2014 - 00:24
Hi I'm using Python and python-requests to communicate with the vuforia api.I have one function to do the authentication and two others to eather update or add a target.The authorisation works so far. I`m able to upload or recieve targets. But it fails when I try to update a target via PUT.I know this is a kind of specific but the server gives me only the error "Fail", witch is not very helpful. This is my implementation: def _get_authenticated_response(self, req): s = Session() prepped = s.prepare_request(req) rfc1123_date = self._get_rfc1123_date() string_to_sign =\ prepped.method + "\n" +\ self._get_content_md5(prepped) + "\n" +\ self._get_content_type(prepped) + "\n" +\ rfc1123_date + "\n" +\ self._get_request_path(prepped) signature = self._hmac_sha1_base64(self.secret_key, string_to_sign) auth_header = 'VWS %s:%s' % (self.access_key, signature) prepped.headers.update({'Date': rfc1123_date, 'Authorization': auth_header}) req = s.send(prepped) return req def add_target(self, data): url = '%s/targets' % self.host data = json.dumps(data) req = Request(method='POST', url=url, headers={'Content-Type':'application/json'}, data=data) response = self._get_authenticated_response(req) return response.json() def update_target(self, target_id, data): # Takes time to process url = '%s/targets/%s' % (self.host, target_id) data = json.dumps(data) req = Request(method='PUT', url=url, headers={'Content-Type':'application/json'}, data=data) response = self._get_authenticated_response(req) return response.json() This is how I use it: upload = v.add_target({"name": str(request.POST['product-name']), "width": str(request.POST['image-width']), "image": image, "active_flag": 0}) But this one fails: edit = v.update_target(target_id="74db*************",data={"name": str(request.POST['product-name']), "width": str(request.POST['image-width']), "image": image, "active_flag": 0})
unclear error message while using VWS-api with PUT
Can you post the entire JSON response body from the service as a string? You should be receiving a more elaborate error response and message.
e.g.
unclear error message while using VWS-api with PUT
You were right. Some targets haven't been successfully processed.
The response message looked like this:
unclear error message while using VWS-api with PUT
You're welcome - so your PUTs are executing properly now?