0

when I'm trying to run my program and insert a record in Cassandra database from Django framework, an error says that: Bad Request: Unknown identifier id What should I do? This is the error:

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 

Model:

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

Views:

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 processes the information received from 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>
ehsan shirzadi
  • 4,709
  • 16
  • 69
  • 112

1 Answers1

1

It sounds like there's a mismatch between the user table schema in cassandra and your User model. What version of cassandra and cqlengine are you using? Could you jump into cqlsh, describe the keyspace the user table is in, and post the output?

Also, I don't know if this is just a test app, but inserting a User row with an id provided by the client is a serious security problem. I could easily take control of another user's account by simply hitting your register_user route with another user's id. You should also be hashing the password, not storing it in plain text.

Blake
  • 841
  • 4
  • 13