Build Cloud-Native apps with Apache Cassandra

GOT QUESTIONS from the Workshop? You're in the right place! Post a question here and we'll get you answers.

Click here for Week 5 Materials and Homework.

Registrations still open!


question

JS avatar image
JS asked ·

Getting "type error: not all arguments converted during string formatting" in cassandra.query.py on Windows

When execute homework Ex05_Query5c_Travel.py, the following error generated. It seems from anaconda2 package. what should I do, thanks.

File "C:/Jie Work/cassandra/Ex05_Query5c_Travel.py", line 36, in <module>
batch.add(prepared_insertLocation, [spacecraft_name, journey_id, Location(x,y,z),readingTime,'AU' ])
File "C:\Users\jie\AppData\Local\Continuum\anaconda2\lib\site-packages\cassandra\query.py", line 829, in add
query_string = bind_params(query_string, parameters, encoder)
File "C:\Users\jie\AppData\Local\Continuum\anaconda2\lib\site-packages\cassandra\query.py", line 896, in bind_params
return query % tuple(encoder.cql_encode_all_types(v) for v in params)
TypeError: not all arguments converted during string formatting
workshop
10 |1000 characters needed characters left characters exceeded

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

1 Answer

bettina.swynnerton avatar image
bettina.swynnerton answered ·

Hi @JS,

it looks like you are running on Windows, and you already have an Anaconda python distribution.

It can be really difficult to understand how dependencies mix and conflict with Python.

For this reason, it is best practice to keep python projects and their dependencies separate. This is generally achieved by creating virtual python environments. The python dependencies needed for a particular project are then installed into a reserved installation of Python and do not mix with other Python installations on your system.

I admit that I have no experience setting up a virtual environment on Windows.

I researched a bit, and the easiest way that I can see is to use an IDE like PyCharm. When you create a new project with PyCharm, it is created in a virtual environment for you, and it is a very easy way to keep your python installations clean of other potentially conflicting dependencies. PyCharm is available as a free community version.

You can look around for other ways of creating a virtual environment, but I would stress that it is really an important step to keep your Python installations clean.

In a fresh virtual environment with Python 3.6 and newer, I would not expect to see the kind of error that you reported.

Does this make sense?


1 comment Share
10 |1000 characters needed characters left characters exceeded

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

Bettina, thank you very much for detailed answer. I agree with what you said. Will try.

JS

0 Likes 0 · ·