You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cassandra.apache.org by Paul van Hoven <pa...@googlemail.com> on 2013/01/23 19:14:42 UTC
Perfroming simple CQL Query using pyhton db-api 2.0 fails
I try to access my local cassandra database via python. Therefore I
installed db-api 2.0 and thrift for accessing the database. Opening
and closing a connection works fine. But a simply query is not
working:
The script looks like this:
c = conn.cursor()
c.execute("""select * from users;""")
data = c.fetchall()
print "Query: select * from users; returned the following result:"
print str(data)
The table users looks like this:
qlsh:demodb> select * from users;
user_name | birth_year | gender | password | session_token | state
-----------+------------+--------+----------+---------------+-------
jsmith | null | null | secret | null | null
But when I try to execute it I get the following error:
Open connection to localhost:9160 on keyspace demodb
Traceback (most recent call last):
File "/Users/Tom/Freelancing/Company/Python/ApacheCassandra/src/CassandraDemo.py",
line 56, in <module>
perfromSimpleCQLQuery()
File "/Users/Tom/Freelancing/Company/Python/ApacheCassandra/src/CassandraDemo.py",
line 46, in perfromSimpleCQLQuery
c.execute("""select * from users;""")
File "/Library/Python/2.7/site-packages/cql/cursor.py", line 81, in execute
return self.process_execution_results(response, decoder=decoder)
File "/Library/Python/2.7/site-packages/cql/thrifteries.py", line
116, in process_execution_results
self.get_metadata_info(self.result[0])
File "/Library/Python/2.7/site-packages/cql/cursor.py", line 97, in
get_metadata_info
name, nbytes, vtype, ctype = self.get_column_metadata(colid)
File "/Library/Python/2.7/site-packages/cql/cursor.py", line 104, in
get_column_metadata
return self.decoder.decode_metadata_and_type(column_id)
File "/Library/Python/2.7/site-packages/cql/decoders.py", line 45,
in decode_metadata_and_type
name = self.name_decode_error(e, namebytes,
comptype.cql_parameterized_type())
File "/Library/Python/2.7/site-packages/cql/decoders.py", line 29,
in name_decode_error
% (namebytes, expectedtype, err))
cql.apivalues.ProgrammingError: column name '\x00\x00\x00' can't be
deserialized as 'org.apache.cassandra.db.marshal.CompositeType':
global name 'self' is not defined
I'm not shure if this is the right place to ask for: But am I doing
here something wrong?
Re: Perfroming simple CQL Query using pyhton db-api 2.0 fails
Posted by Paul van Hoven <pa...@googlemail.com>.
The reason for the error was that I opened the connection to the database wrong.
I did:
con = cql.connect(host, port, keyspace)
but correct is:
con = cql.connect(host, port, keyspace, cql_version='3.0.0')
Now it works fine. Thanks for reading.
2013/1/24 aaron morton <aa...@thelastpickle.com>:
> How did you create the table?
>
> Anyways that looks like a bug, I *think* they should go here
> http://code.google.com/a/apache-extras.org/p/cassandra-dbapi2/issues/list
>
> Cheers
>
> -----------------
> Aaron Morton
> Freelance Cassandra Developer
> New Zealand
>
> @aaronmorton
> http://www.thelastpickle.com
>
> On 24/01/2013, at 7:14 AM, Paul van Hoven <pa...@googlemail.com>
> wrote:
>
> I try to access my local cassandra database via python. Therefore I
> installed db-api 2.0 and thrift for accessing the database. Opening
> and closing a connection works fine. But a simply query is not
> working:
>
> The script looks like this:
>
> c = conn.cursor()
> c.execute("""select * from users;""")
> data = c.fetchall()
> print "Query: select * from users; returned the following result:"
> print str(data)
>
>
> The table users looks like this:
> qlsh:demodb> select * from users;
>
> user_name | birth_year | gender | password | session_token | state
> -----------+------------+--------+----------+---------------+-------
> jsmith | null | null | secret | null | null
>
>
>
> But when I try to execute it I get the following error:
> Open connection to localhost:9160 on keyspace demodb
> Traceback (most recent call last):
> File
> "/Users/Tom/Freelancing/Company/Python/ApacheCassandra/src/CassandraDemo.py",
> line 56, in <module>
> perfromSimpleCQLQuery()
> File
> "/Users/Tom/Freelancing/Company/Python/ApacheCassandra/src/CassandraDemo.py",
> line 46, in perfromSimpleCQLQuery
> c.execute("""select * from users;""")
> File "/Library/Python/2.7/site-packages/cql/cursor.py", line 81, in execute
> return self.process_execution_results(response, decoder=decoder)
> File "/Library/Python/2.7/site-packages/cql/thrifteries.py", line
> 116, in process_execution_results
> self.get_metadata_info(self.result[0])
> File "/Library/Python/2.7/site-packages/cql/cursor.py", line 97, in
> get_metadata_info
> name, nbytes, vtype, ctype = self.get_column_metadata(colid)
> File "/Library/Python/2.7/site-packages/cql/cursor.py", line 104, in
> get_column_metadata
> return self.decoder.decode_metadata_and_type(column_id)
> File "/Library/Python/2.7/site-packages/cql/decoders.py", line 45,
> in decode_metadata_and_type
> name = self.name_decode_error(e, namebytes,
> comptype.cql_parameterized_type())
> File "/Library/Python/2.7/site-packages/cql/decoders.py", line 29,
> in name_decode_error
> % (namebytes, expectedtype, err))
> cql.apivalues.ProgrammingError: column name '\x00\x00\x00' can't be
> deserialized as 'org.apache.cassandra.db.marshal.CompositeType':
> global name 'self' is not defined
>
> I'm not shure if this is the right place to ask for: But am I doing
> here something wrong?
>
>
Re: Perfroming simple CQL Query using pyhton db-api 2.0 fails
Posted by aaron morton <aa...@thelastpickle.com>.
How did you create the table?
Anyways that looks like a bug, I *think* they should go here http://code.google.com/a/apache-extras.org/p/cassandra-dbapi2/issues/list
Cheers
-----------------
Aaron Morton
Freelance Cassandra Developer
New Zealand
@aaronmorton
http://www.thelastpickle.com
On 24/01/2013, at 7:14 AM, Paul van Hoven <pa...@googlemail.com> wrote:
> I try to access my local cassandra database via python. Therefore I
> installed db-api 2.0 and thrift for accessing the database. Opening
> and closing a connection works fine. But a simply query is not
> working:
>
> The script looks like this:
>
> c = conn.cursor()
> c.execute("""select * from users;""")
> data = c.fetchall()
> print "Query: select * from users; returned the following result:"
> print str(data)
>
>
> The table users looks like this:
> qlsh:demodb> select * from users;
>
> user_name | birth_year | gender | password | session_token | state
> -----------+------------+--------+----------+---------------+-------
> jsmith | null | null | secret | null | null
>
>
>
> But when I try to execute it I get the following error:
> Open connection to localhost:9160 on keyspace demodb
> Traceback (most recent call last):
> File "/Users/Tom/Freelancing/Company/Python/ApacheCassandra/src/CassandraDemo.py",
> line 56, in <module>
> perfromSimpleCQLQuery()
> File "/Users/Tom/Freelancing/Company/Python/ApacheCassandra/src/CassandraDemo.py",
> line 46, in perfromSimpleCQLQuery
> c.execute("""select * from users;""")
> File "/Library/Python/2.7/site-packages/cql/cursor.py", line 81, in execute
> return self.process_execution_results(response, decoder=decoder)
> File "/Library/Python/2.7/site-packages/cql/thrifteries.py", line
> 116, in process_execution_results
> self.get_metadata_info(self.result[0])
> File "/Library/Python/2.7/site-packages/cql/cursor.py", line 97, in
> get_metadata_info
> name, nbytes, vtype, ctype = self.get_column_metadata(colid)
> File "/Library/Python/2.7/site-packages/cql/cursor.py", line 104, in
> get_column_metadata
> return self.decoder.decode_metadata_and_type(column_id)
> File "/Library/Python/2.7/site-packages/cql/decoders.py", line 45,
> in decode_metadata_and_type
> name = self.name_decode_error(e, namebytes,
> comptype.cql_parameterized_type())
> File "/Library/Python/2.7/site-packages/cql/decoders.py", line 29,
> in name_decode_error
> % (namebytes, expectedtype, err))
> cql.apivalues.ProgrammingError: column name '\x00\x00\x00' can't be
> deserialized as 'org.apache.cassandra.db.marshal.CompositeType':
> global name 'self' is not defined
>
> I'm not shure if this is the right place to ask for: But am I doing
> here something wrong?