TypeError: Object of type int64 is not JSON serializable

1,155 views
Skip to first unread message

Johan Antonissen

unread,
Jul 22, 2022, 11:30:51 AM7/22/22
to VPython-users
Hi there,

Im gettig a weird error in vpython. I have r a progrem where i can create a closet, for some values it gives the below error.

This is the link to my github: https://github.com/deWasbeer/hout-topologie
The program works by first running main.py and when thats finished running main2.py.

The error can be reproduced by using the following values:

width 400
height 200
depth 80
width 40
height 3
langth 400
height 10

It's attatched below. Any idea what could cause this ?

I'm running vpython-7.6.4 on chromeOS with the following linux container:

lsb_release -a
hostnamectl
PRETTY_NAME="Debian GNU/Linux bookworm/sid"
NAME="Debian GNU/Linux"
ID=debian
HOME_URL="https://www.debian.org/"
SUPPORT_URL="https://www.debian.org/support"
BUG_REPORT_URL="https://bugs.debian.org/"
No LSB modules are available.
Distributor ID: Debian
Description:    Debian GNU/Linux bookworm/sid
Release:        11-updates
Codename:       n/a
   Static hostname: penguin
         Icon name: computer-container
           Chassis: container
    Virtualization: lxc
  Operating System: Debian GNU/Linux bookworm/sid
            Kernel: Linux 5.10.114-16024-gbdf1547bd4f4
      Architecture: x86-64

Error:

future: <Task finished name='Task-125' coro=<WSserver.onMessage() done, defined at /home/windhoos/.local/lib/python3.10/site-packages/vpython/no_notebook.py:181> exception=TypeError('Object of type int64 is not JSON serializable')>
Traceback (most recent call last):
  File "/home/windhoos/.local/lib/python3.10/site-packages/vpython/no_notebook.py", line 203, in onMessage
    jdata = json.dumps(objdata, separators=(',', ':')).encode('utf_8')
  File "/usr/lib/python3.10/json/__init__.py", line 238, in dumps
    **kw).encode(obj)
  File "/usr/lib/python3.10/json/encoder.py", line 199, in encode
    chunks = self.iterencode(o, _one_shot=True)
  File "/usr/lib/python3.10/json/encoder.py", line 257, in iterencode
    return _iterencode(o, 0)
  File "/usr/lib/python3.10/json/encoder.py", line 179, in default
    raise TypeError(f'Object of type {o.__class__.__name__} '
TypeError: Object of type int64 is not JSON serializable

Steve Spicklemire

unread,
Jul 22, 2022, 11:55:49 AM7/22/22
to vpytho...@googlegroups.com, Steve Spicklemire
That’s a pretty complicated example. Any chance you could narrow it down to a simpler example that exhibits the problem?

-steve
> --
> You received this message because you are subscribed to the Google Groups "VPython-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to vpython-user...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/vpython-users/1682d3c1-092c-4105-9945-1b68074ba98en%40googlegroups.com.

Johan Antonissen

unread,
Jul 22, 2022, 1:53:48 PM7/22/22
to VPython-users
Hi there,

Thank you for the reply. Unfortunatley i cant. This is becaise the error is not thrown by my python code but the vpython library. When i get an error in my code or a library related code the error font is in color and i see the redirection to the lines where the error comes from. In this error, there is no redirection to my own code and the code in the consol is white....

Johan Antonissen

unread,
Jul 22, 2022, 1:54:47 PM7/22/22
to VPython-users
Screenshot 2022-07-22 7.54.25 PM.png

Johan Antonissen

unread,
Jul 22, 2022, 4:39:19 PM7/22/22
to VPython-users
okay i managed ti trace it down a bit. I think the problem arises when for the thickness of a plank a whole number is inserted.
i changed to float but that did not sove the problem.

What also weird is, in phase 1 of the program (main.py) everything works fine.
In the second phase of the program (main2.py) the first step works fine, the error arises at step two. however it fails at the exact same plank that was drawn in step1.
Also the error is not consistent. Sometimes the program crashes after drawing 1 feet, sometimes after 4 feet etcetera. This is for the exact same input, the only thing that differs is that i run the program on a different time...

Finally since the error given does not lead back to my own code it makes it very difficult to debug :(

Bruce Sherwood

unread,
Jul 22, 2022, 5:03:26 PM7/22/22
to VPython-users
I suggest inserting some diagnostic print statements just before the point at which the error occurs. 

Note too that you might fruitfully put some print statements in encoder.py, not just in your own code.

Bruce

Johan Antonissen

unread,
Jul 23, 2022, 3:51:49 AM7/23/22
to VPython-users
okay i'm  going for a deep dive :) Thought i might have found a bug in vpython since it was thrown in the part thats run when jupiter is not used.
Reply all
Reply to author
Forward
0 new messages