错误请求:未知标识符ID

时间:2014-01-11 13:26:03

标签: python django cassandra cqlengine

当我尝试运行我的程序并从Django框架在Cassandra数据库中插入记录时,出现错误:Bad Request:Unknown identifier id 我该怎么办? 这是错误:

CQLEngineException at /registered/

Bad Request: Unknown identifier id

Request Method:     GET
Request URL:    http://127.0.0.1:8000/registered/?txtID=3&txtName=3&txtUsername=3&txtPassword=3
Django Version:     1.5.1
Exception Type:     CQLEngineException
Exception Value:    

Bad Request: Unknown identifier id

Exception Location:     C:\Python27\lib\site-packages\cqlengine\connection.py in execute, line 221
Python Executable:  C:\Python27\python.exe
Python Version:     2.7.4
Python Path:    

['D:\\Developer Center\\PyCharm\\Bookstore',
 'C:\\Python27\\lib\\site-packages\\pip-1.3.1-py2.7.egg',
 'C:\\Python27\\lib\\site-packages\\mysql_python-1.2.4-py2.7-win32.egg',
 'D:\\Developer Center\\PyCharm\\Bookstore',
 'C:\\Windows\\SYSTEM32\\python27.zip',
 'C:\\Python27\\DLLs',
 'C:\\Python27\\lib',
 'C:\\Python27\\lib\\plat-win',
 'C:\\Python27\\lib\\lib-tk',
 'C:\\Python27',
 'C:\\Python27\\lib\\site-packages',
 'C:\\Python27\\lib\\site-packages\\PIL']

Server time:    Sat, 11 Jan 2014 16:48:09 +0330
Traceback Switch to copy-and-paste view

    C:\Python27\lib\site-packages\django\core\handlers\base.py in get_response

                                response = callback(request, *callback_args, **callback_kwargs)

        ...
    ▶ Local vars
    D:\Developer Center\PyCharm\Bookstore\BookstoreApp\views.py in register_user

            User.create(id=str(id),name=name,username=username,password=password)

        ...
    ▶ Local vars
    C:\Python27\lib\site-packages\cqlengine\models.py in create

                return cls.objects.create(**kwargs)

        ...
    ▶ Local vars
    C:\Python27\lib\site-packages\cqlengine\query.py in create

                return self.model(**kwargs).batch(self._batch).save()

        ...
    ▶ Local vars
    C:\Python27\lib\site-packages\cqlengine\models.py in save

                self.__dmlquery__(self.__class__, self, batch=self._batch).save()

        ...
    ▶ Local vars
    C:\Python27\lib\site-packages\cqlengine\query.py in save

                        execute(qs, query_values)

        ...
    ▶ Local vars
    C:\Python27\lib\site-packages\cqlengine\connection.py in execute

            return connection_pool.execute(query, params)

        ...
    ▶ Local vars
    C:\Python27\lib\site-packages\cqlengine\connection.py in execute

                        raise CQLEngineException(unicode(ex))

        ...
    ▶ Local vars 

型号:

class User(Model):
    id = columns.Text(primary_key=True)
    name = columns.Text()
    username = columns.Text()
    password = columns.Text()

观点:

def register_form(request):
    return render_to_response('registration.html')

def register_user(request):
    connection.setup(['127.0.0.1:9160'])
    sync_table(User)
    id = request.GET['txtID']
    name = request.GET['txtName']
    username = request.GET['txtUsername']
    password = request.GET['txtPassword']
    User.create(id=str(id),name=name,username=username,password=password)
    return render_to_response('OK')

register_user处理从registration.html

收到的信息

registration.html

<!DOCTYPE html>
<html>
<head>
    <title>Registration</title>
</head>
<body>
    <form action="/registered/" method="get">
    <ul>
        <li>
            <label>ID</label>
            <input ty="text" name="txtID">
        </li>
        <li>
            <label>Username</label>
            <input ty="text" name="txtName">
        </li>
        <li>
            <label>Username</label>
            <input ty="text" name="txtUsername">
        </li>
        <li>
            <label>Password</label>
            <input ty="text" name="txtPassword">
        </li>
        <li>
            <label></label>
            <input type="submit" value="Register">
        </li>
    </ul>
    </form>
</body>
</html>

1 个答案:

答案 0 :(得分:1)

听起来cassandra中的用户表架构与用户模型之间存在不匹配。您使用的是什么版本的cassandra和cqlengine?你能跳进cqlsh,描述用户表所在的键空间,并发布输出吗?

此外,我不知道这是否只是一个测试应用程序,但插入客户端提供的ID的用户行是一个严重的安全问题。我可以通过简单地用另一个用户的id命中你的register_user路由来轻松控制另一个用户的帐户。您还应该对密码进行哈希处理,而不是以纯文本格式存储。