cryptoadvance / specter-desktop

A desktop GUI for Bitcoin Core optimised to work with hardware wallets

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

TypeError: 'float' object cannot be interpreted as an integer - Python 3.12

bitcoinlizard opened this issue · comments

Describe the bug
I have been maintaining an Arch Linux package for Specter Desktop. Arch recently moved to Python 3.12 and I suspect the Python upgrade is responsible for a behavior change in random.py which breaks the run process.

To Reproduce
Steps to reproduce the behavior:
Run Specter Desktop with this command on Arch Linux running Python 3.12:
python -m cryptoadvance.specter server --debug

Expected behavior
Specter Desktop should run normally as it did in Python 3.11 on Arch Linux

Desktop (please complete the following information):

  • Arch Linux
  • Running at Arch Linux CLI
  • Specter Version 2.0.5

Additional context
Here is the full error message:
$ python -m cryptoadvance.specter server --debug
Traceback (most recent call last):
File "", line 198, in _run_module_as_main
File "", line 88, in _run_code
File "/usr/lib/python3.12/site-packages/cryptoadvance/specter/main.py", line 2, in
from .cli import entry_point
File "/usr/lib/python3.12/site-packages/cryptoadvance/specter/cli/init.py", line 6, in
from ..server import setup_logging
File "/usr/lib/python3.12/site-packages/cryptoadvance/specter/server.py", line 31, in
from .hwi_server import hwi_server
File "/usr/lib/python3.12/site-packages/cryptoadvance/specter/hwi_server.py", line 14, in
rand = random.randint(0, 1e32) # to force style refresh
^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.12/random.py", line 336, in randint
return self.randrange(a, b+1)
^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.12/random.py", line 312, in randrange
istop = _index(stop)
^^^^^^^^^^^^
TypeError: 'float' object cannot be interpreted as an integer

It seems that in Python 3.12 there was a change to the random library. "random.randint" will not accept "1e32" because the python exponent function returns an float instead of an integer. A work around would be to change the offending line to:

rand = random.randint(0, int(1e32))

This line is used in a number of spots in Specter.