Log in or register to post comments

unclear error message while using VWS-api with PUT

January 8, 2014 - 4:24pm #1
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

January 9, 2014 - 6:22pm #4

You're welcome - so your PUTs are executing properly now?

unclear error message while using VWS-api with PUT

January 9, 2014 - 4:54pm #3

You were right. Some targets haven't been successfully processed.

The response message looked like this:

{"result_code":"Fail","transaction_id":"fa348c2ed9ea41cabe5239c376604877"}

This is how the requests body looks:

{"active_flag": 0, "width": "125", "image": "TkRibrCrMRGga4WKLtfHVO...", "name": "something"}

Thanks for the hint with the image processing. What a stupid mistake. I would never have found the problem by working on my code.

unclear error message while using VWS-api with PUT

January 8, 2014 - 4:50pm #2

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.

{"result_code":"AuthenticationFailure","transaction_id":"fa348c2ed9ea41cabe5239c376604877"}

 

Also be sure that the target you are adding has been processed successfully before attempting to update it.

If you are, then it's possible that you are receiving an authentication error due to the format(s) of the of the elements of your request signature. That's a common problem. Check that the width you are defining is a float ( e.g. 100.0 ) and that the strings you are formatting don't contain unnecessary spaces or character entities.

Log in or register to post comments