The following code results in an error on put_item. I have a .boto file and the connection works fine. Unfortunately this always gets this error on put_item:--boto.exception.JSONResponseError: JSONResponseError: 400 Bad Request{'Message': 'Expected null', '__type': 'com.amazon.coral.service#SerializationException'}I have already created the table and the primary key type is Hash and called id. I have given the necessary permissions.#!/usr/bin/env python3
""" Game server.
Usage:
python3 main.py <debug>
"""
# Imports
import boto
from boto.dynamodb2.table import Table
from boto.dynamodb2.layer1 import DynamoDBConnection
from datetime import datetime
from flask import *
from random import shuffle
import sys
import uuid
# Constants
TOKEN = 'Some Token'
AWS_REGION = 'us-east-2'
# Modules
app = Flask(__name__)
conn = boto.dynamodb2.connect_to_region(region_name=AWS_REGION)
games = Table('games', connection=conn)
@app.route('/game-server/api/v1.0/create_new_game/<token>/<player_1>/<player_2>/<rules>',
methods=['GET'])
def create_new_game(token, player_1, player_2, rules):
"""Creates a new game from scratch
:param token: Unique value that verifies the caller is valid
:param player_1: Name of the first player
:param player_2: Name of the second player
:param rules: String representing the rules to be used in the game
:return: UUID representing the game id that has been created
"""
# Create game
game_id = str(uuid.uuid4())
item_data = {
'id': game_id,
'created': str(datetime.utcnow()),
}
conn.put_item('games', item=item_data)
return game_id
# Main entry point
if __name__ == "__main__":
app.run(debug=True, port=8192)
You received this message because you are subscribed to the Google Groups "boto-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to boto-users+...@googlegroups.com.
To post to this group, send email to boto-...@googlegroups.com.
Visit this group at http://groups.google.com/group/boto-users.
For more options, visit https://groups.google.com/d/optout.
item_data = {
'id': {'S': game_id},
'created': {'S': str(datetime.utcnow())},
}
--
You received this message because you are subscribed to a topic in the Google Groups "boto-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/boto-users/ITlD-4Qsf9c/unsubscribe.
To unsubscribe from this group and all its topics, send an email to boto-users+...@googlegroups.com.
To post to this group, send email to boto-...@googlegroups.com.
Visit this group at http://groups.google.com/group/boto-users.
For more options, visit https://groups.google.com/d/optout.
Ok, figured out the issue. The Item and Key fields have to be wrapped with the data types in the layer1 API so OP's request should be:item_data = {
'id': {'S': game_id},
'created': {'S': str(datetime.utcnow())},
}
--Danny