Android Amazon DynamoDB 400错误请求错误

时间:2014-09-11 06:12:14

标签: android amazon-dynamodb

我正在尝试在我的Android应用程序中实现Amazon Dynamo DB。使用诸如id(字符串),状态(数字)之类的属性创建的表。我收到AmazonClientException为"无法解组错误响应"。有人建议我。

这里我的代码是..

   try {
           AmazonDynamoDBClient ddb = DynamoDB.getInstance();

                 Map<String, AttributeValue> item = new HashMap<String, AttributeValue>();
                 item.put("googleid", new AttributeValue().withS("Test"));
                 item.put("status", new AttributeValue().withN("1234"));

                 PutItemRequest putItemRequest =  new PutItemRequest("android_news_push",  item);
                 PutItemResult putItemResult = ddb.putItem(putItemRequest);
    } catch (AmazonServiceException e) {
     // TODO Auto-generated catch block
    e.printStackTrace();
    } catch (AmazonClientException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }

我的例外是:

 09-11 05:58:14.473: W/System.err(1661): com.amazonaws.AmazonClientException: Unable to unmarshall error response (Unable to parse error response: '<?xml version="1.0" encoding="UTF-8"?><Error><Code>UnsignedContentSHA256NotAllowed</Code><Message>The provided 'x-amz-content-sha256' header must be a valid SHA256.</Message><RequestId>B5B29CD73F1304CE</RequestId><HostId>qqkdFlfHognQw3zs//OcdyN9GDXDd84MFyi01ep8iMfseGFkz3z+MS9etRssS76v0H+A0IyJH1M=</HostId></Error>'). Response Code: 400, Response Text: Bad Request
09-11 05:58:14.473: W/System.err(1661):     at com.amazonaws.http.AmazonHttpClient.handleErrorResponse(Unknown Source)
09-11 05:58:14.473: W/System.err(1661):     at com.amazonaws.http.AmazonHttpClient.executeHelper(Unknown Source)
09-11 05:58:14.473: W/System.err(1661):     at com.amazonaws.http.AmazonHttpClient.execute(Unknown Source)
09-11 05:58:14.473: W/System.err(1661):     at com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient.invoke(Unknown Source)
09-11 05:58:14.473: W/System.err(1661):     at com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient.putItem(Unknown Source)
09-11 05:58:14.473: W/System.err(1661):     at com.dci.magzter.SplashScreen$4.onPostExecute(SplashScreen.java:260)
09-11 05:58:14.473: W/System.err(1661):     at com.dci.magzter.SplashScreen$4.onPostExecute(SplashScreen.java:1)
09-11 05:58:14.473: W/System.err(1661):     at com.dci.magzter.utils.AsyncTask.finish(AsyncTask.java:640)
09-11 05:58:14.473: W/System.err(1661):     at com.dci.magzter.utils.AsyncTask.access$0(AsyncTask.java:636)
09-11 05:58:14.473: W/System.err(1661):     at com.dci.magzter.utils.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:653)
09-11 05:58:14.473: W/System.err(1661):     at android.os.Handler.dispatchMessage(Handler.java:99)
09-11 05:58:14.473: W/System.err(1661):     at android.os.Looper.loop(Looper.java:137)
09-11 05:58:14.473: W/System.err(1661):     at android.app.ActivityThread.main(ActivityThread.java:4745)
09-11 05:58:14.473: W/System.err(1661):     at java.lang.reflect.Method.invokeNative(Native Method)
09-11 05:58:14.473: W/System.err(1661):     at java.lang.reflect.Method.invoke(Method.java:511)
09-11 05:58:14.473: W/System.err(1661):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
09-11 05:58:14.473: W/System.err(1661):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
09-11 05:58:14.473: W/System.err(1661):     at dalvik.system.NativeStart.main(Native Method)
09-11 05:58:14.473: W/System.err(1661): Caused by: com.amazonaws.AmazonClientException: Unable to parse error response: '<?xml version="1.0" encoding="UTF-8"?><Error><Code>UnsignedContentSHA256NotAllowed</Code><Message>The provided 'x-amz-content-sha256' header must be a valid SHA256.</Message><RequestId>B5B29CD73F1304CE</RequestId><HostId>qqkdFlfHognQw3zs//OcdyN9GDXDd84MFyi01ep8iMfseGFkz3z+MS9etRssS76v0H+A0IyJH1M=</HostId></Error>'
09-11 05:58:14.473: W/System.err(1661):     at com.amazonaws.http.JsonErrorResponseHandler.handle(Unknown Source)
09-11 05:58:14.473: W/System.err(1661):     at com.amazonaws.http.JsonErrorResponseHandler.handle(Unknown Source)
09-11 05:58:14.473: W/System.err(1661):     ... 18 more
09-11 05:58:14.473: W/System.err(1661): Caused by: com.amazonaws.util.json.JSONException: A JSONObject text must begin with '{' at 1 [character 2 line 1]
09-11 05:58:14.473: W/System.err(1661):     at com.amazonaws.util.json.JSONTokener.syntaxError(Unknown Source)
09-11 05:58:14.473: W/System.err(1661):     at com.amazonaws.util.json.JSONObject.<init>(Unknown Source)
09-11 05:58:14.473: W/System.err(1661):     at com.amazonaws.util.json.JSONObject.<init>(Unknown Source)
09-11 05:58:14.473: W/System.err(1661):     ... 20 more

1 个答案:

答案 0 :(得分:0)

您的AWS凭据似乎有问题。检查您的密钥是否正确,并检查访问控制是否允许该操作。

您可以看到类似的问题here

希望它有所帮助...