TypeError: object of type 'Cursor' has no len()

typeerror: object of type is not json serializable
typeerror: object of type 'bytes' is not json serializable flask
typeerror: object of type method is not json serializable
typeerror: object of type 'dict_values' is not json serializable
typeerror: object of type session is not json serializable
typeerror: object of type message is not json serializable
typeerror object of type columnclause is not json serializable
typeerror: object of type 'posixpath' is not json serializable

I get this error:

TypeError: object of type 'Cursor' has no len()

when I try to execute:

reply = db['test'].find({"date":{"$gt":date_query}} ,{"date":1,"route_id":1,"loc":1,"_id":0})

length = len(reply)

The pymongo cursor has a method count() which will return what you're looking for:

reply = db['test'].find(
  {"date":{"$gt":date_query}},
  {"date":1,"route_id":1,"loc":1,"_id":0}
)

length = reply.count()

TypeError: Object of type 'date' is not JSON serializable when using , TypeError: Object of type 'date' is not JSON serializable when using mkdocs serve #1961. Open. BrianSidebotham opened this issue on Jan 15 · 2 comments. Stack Overflow for Teams is a private, secure spot for you and your coworkers to find and share information. 122 123 if num < 0: TypeError: object of type <class

Yes, count will do the work for you.

length = reply.count() 

or

length = reply.count(with_limit_and_skip=False)

had to suffer a lot coz length = count(reply) also did not work. Since I'm not allowed to comment yet, thought to leave this answer. Hope this will help somebody to save some time.

TypeError: Object of type QueryExecutionError is not JSON , Issue Summary While testing the latest master, I started noticing this error pop up in our Sentry. Steps to Reproduce Run a query that fails to  Describe the bug Training model with validate would run into error like this: TypeError: object of type <class 'numpy.float64'> cannot be safely interpreted as an

Starting Mongo 4.0.3/PyMongo 3.7.0, you could alternatively use count_documents instead of count on a cursor:

db.collection.count_documents({ "a": 2 })
# where { "a": 2 } is whatever filtering query

db.collection.count_documents is the alternative to the now deprecated db.collection.count.

Python: Altair, Learn how to solve the TypeError: Object of type date is not JSON serializable error when rendering Altair charts. When it goes to check if the user has entered 7 digits it gives me this error: TypeError: object of type 'int' has no len()

Why am i getting this error TypeError: Object of type bytes is not , I have the below code, when i run it i get this error in my jupyter notetbook: TypeError: Object of type bytes is not JSON serializable. import  gives me: TypeError: Object of type float32 is not JSON serializable while if I convert to 64 bit floating point values before serialising to JSON, it works: json.dumps(list(arr.astype(float)))

TypeError: object of type 'Bidirectional' has no len(), That code instantiates model over and over. model should be instantiated once and all other layers are added to that instance. Something like  Stack Overflow for Teams is a private, secure spot for you and your coworkers to find and share information. Learn more Python: TypeError: object of type 'NoneType' has no len()

TypeError: Object of type is not JSON serializable, TypeError: Object of type is not JSON serializable. Python flask-sqlalchemy model objects is not json serializable. If your code returns query  raise TypeError(TypeError: object of type <class 'numpy.float64'> cannot be safely interpreted as an integer.

Comments
  • this is because all you did was define the cursor which is a query request for the server - you didn't actually get a set of results back (because normally you would iterate over a cursor getting batches of documents at a time).