python-build-standalone: `uuid.get_node` is failing to find a stable identifier
❯ uvx python -c "import uuid; print(uuid.getnode())"
87776899200804
❯ uvx python -c "import uuid; print(uuid.getnode())"
16554352112436
❯ uvx --no-managed-python python -c "import uuid; print(uuid.getnode())"
178803724683704
❯ uvx --no-managed-python python -c "import uuid; print(uuid.getnode())"
178803724683704
https://docs.python.org/3/library/uuid.html#uuid.getnode
… If all attempts to obtain the hardware address fail, we choose a random 48-bit number with the multicast bit (least significant bit of the first octet) set to 1 as recommended in RFC 4122.
About this issue
- Original URL
- State: open
- Created 2 years ago
- Reactions: 2
- Comments: 19 (11 by maintainers)
Commits related to this issue
- Rename stable_random_machine_id to machine_id_v4 / installation_id_v4 (#11138) ## Describe your changes Rename the new `stableRandomMachineId` to `machineIdV4` to make it clear (1) we can't rely on ... — committed to streamlit/streamlit by sfc-gh-tteixeira 2 years ago
- Add patch for stable `uuid.getnode` on 3.13 (#634) Cherry-picks https://github.com/python/cpython/pull/134704 See #587 — committed to astral-sh/python-build-standalone by zanieb a year ago
This feels like a CPython bug/quirk. The code prefers obtaining a random time for the node value on Linux if a C function is available. It then falls back to trying to find an actual hardware value.
Feels like the ordering is wrong. But this may have been a choice to favor performance or security or something. But it isn’t documented inline in uuid.py.