Ошибка проверки DynamoDB 400 Неверный запрос

#python #python-2.7 #amazon-web-services

#python #python-2.7 #amazon-веб-сервисы

Вопрос:

Я некоторое время ломал голову над этим. Кто-нибудь видит, в чем проблема:

Код:

 x=None
y=None
split = key.split("/")
if ".svg" in loc:
    svgF=open(loc,"r").read()
    svg = etree.fromstring(svgF)
    x = svg.xpath("//@width")[0]
    x=x[:x.__len__()-4]
    y = svg.xpath("//@height")[0]
    y=y[:y.__len__()-4]
elif ".swf" not in loc:
    i=Image.open(loc)
    dim = i.size
    x=dim[0]
    y=dim[1]
data={}
data["x"]=x
data["y"]=y
data["primary color"]="none"
data["secondary color"]= "none"
data["tertiary color"]="none"
data["time"]=str(getTimeAsInt)
data["parent"]=split[1] split[2]

newI = imageTable.new_item(split[1] split[2] split[11],"image", data)
#try:
newI.save()
return(split[1] split[2] split[11])
#except:
#    pass
split[1] split[2] split[11]
  

Ошибка:

Файл «/Users/tai/Documents/workspace/testSelenium/testS/database.py «, строка 188, в файле recursiveInnerFile dynamoStorage.SaveImage(loc, ключ) «/Users/tai/Documents/workspace/testSelenium/testS/dynamoStorage.py «, строка 161, в файле SaveImage newI.save() «/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/boto/dynamodb/item.py «, строка 141, в сохранить возвращаемые значения) Файл «/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/boto/dynamodb/layer2.py «, строка 592, в update_item object_hook=self.dynamizer.decode) Файл «/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/boto/dynamodb/layer1.py «, строка 425, в файле update_item object_hook=object_hook) «/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/boto/dynamodb/layer1.py «, строка 119, в make_request retry_handler=self._retry_handler) Файл «/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/boto/connection.py «, строка 932, в _mexe status = retry_handler (ответ, i, next_sleep) Файл «/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/boto/dynamodb/layer1.py «, строка 156, в _retry_handler response.status, ответ.причина, данные) boto.dynamodb.exceptions.Ошибка DynamoDBValidationError: DynamoDBValidationError: 400 неверный запрос {u’message’: u’одно или более значений параметра были недопустимыми: разрешено только действие УДАЛЕНИЯ, когда не указано значение атрибута’, u’__type’: u’com.amazon.coral.validate#ValidationException’}

Когда я изменяю эту строку следующим образом:

  newI = imageTable.new_item(data["parent"], data)
  

Я не получаю сообщение об ошибке, однако информация хранится в dynamo некорректно. Я получаю только идентификатор и никаких других столбцов.

Кроме того, для моего текста, который настроен очень похоже, это работает нормально:

         newI = textTable.new_item(split[1] split[2] split[11],item_data["time"], item_data)
  

текстовый код:

 #TODO this will not work ID is unique only for the swf, not for the text file, it will need each   text
def createText(loc,theNewKey):
with open(loc, "r") as myfile:
    item_data={}
    item_data["time"] = int(getTimeAsInt())
    theText=""
    inText=False
    count = 0;
    split = theNewKey.split("/")
    for line in myfile:
        if line.__len__() >3:
            #if the line starts with text
            if line[0]=="]" and line[1] !="[":
                if("[" in line):
                    line=re.sub("[][]","",line)
                    inText= False;
                    item_data["display_text" str(count)]=""
                    item_data["display_text" str(count)] = item_data["display_text" str(count)]   " "   line[0:line.__len__()]
                    count =1
                    #if the line does not end the next line will also contain text
                else:
                    line=re.sub("[]]","",line)
                    inText=True
                    #for some reason adding this line fixes the concatenation issue
                    item_data["display_text" str(count)]=""
                    item_data["display_text" str(count)] = item_data["display_text" str(count)]   " "   line[0:line.__len__()]
                theText =" "   line
            elif line is not None and inText is False:
                splitL= line.split(" ");
                if splitL is not None and splitL.__len__()>=2:
                    place = splitL[0]
                    item_data[place str(count)]=splitL[1]
            elif inText:
                if("[" in line):
                    inText=False
                    re.sub("][","",line)
                    item_data["display_text" str(count)] =" " line
                    count =1
                else:
                    re.sub("][","",line)
                    item_data["display_text" str(count)] =" " line
                theText =" "   line
        elif("[" in line):
            if inText:
                inText = False
                count =1
    item_data["parent"]=split[1] split[2]
    newI = textTable.new_item(split[1] split[2] split[11],item_data["time"], item_data)
    try:
        newI.save()
        return(split[1] split[2] split[11])
    except:
        pass
  

Комментарии:

1. Что это key ? Какой тип imageTable ? Я понимаю, что вы пытаетесь сделать, но, не видя, как работает ваш new_item метод и как выглядит ваша схема БД, трудно сказать, где ошибка.

2. ключ такой же, как myNewKey в рабочей функции. Таблица изображений не имеет типа (не уверен)