Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

uuid.getnode() is not tied to MAC address when usinglibuuid #132710

Closed
Assignees
picnixz
Labels
extension-modulesC modules in the Modules dirstdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error
@sfc-gh-tteixeira

Description

@sfc-gh-tteixeira

Bug report

Bug description:

According to the docs,uuid.getnode() is meant to return a number based on the MAC address of the network interface. However, if Python is built withlibuuid, this does not match the observed behavior. Instead,getnode() often produces a random number.

Versions of Python obtained through python.org,brew, andpyenv don't appear to display this bug. But versions obtained throughuv andpython-build-standalone do.

The key difference seems to be which branch of thistry block insideuuid.py is executed:

# Import optional C extension at toplevel, to help disabling it when testingtry:import_uuid_generate_time_safe=getattr(_uuid,"generate_time_safe",None)_UuidCreate=getattr(_uuid,"UuidCreate",None)_has_uuid_generate_time_safe=_uuid.has_uuid_generate_time_safeexceptImportError:_uuid=None_generate_time_safe=None_UuidCreate=None_has_uuid_generate_time_safe=None

When the top branch executes,getnode() produces a random number.
When the bottom branch executes,getnode() produces a number tied to the MAC address of the network interface.

Steps to reproduce:

Case 1: working as intended

Using a version of Python compiled with these flags...

        HAVE_UUID_CREATE = "0"        HAVE_UUID_ENC_BE = "0"        HAVE_UUID_GENERATE_TIME_SAFE = "1"        HAVE_UUID_H = "1"        HAVE_UUID_UUID_H = "1"

...we get this behavior:

$python -c"import uuid; print(uuid.getnode())"some number X$python -c"import uuid; print(uuid.getnode())"the same number X

Case 2: buggy behavior

Using a version of Python compiled with these flags...

        HAVE_UUID_CREATE = "0"        HAVE_UUID_ENC_BE = "0"        HAVE_UUID_GENERATE_TIME_SAFE = "0"        HAVE_UUID_H = "0"        HAVE_UUID_UUID_H = "1"

...we get this behavior:

$python -c"import uuid; print(uuid.getnode())"some number X$python -c"import uuid; print(uuid.getnode())"some other number Y!!!

CPython versions tested on:

3.13

Operating systems tested on:

macOS, Linux

Linked PRs

Metadata

Metadata

Assignees

Labels

extension-modulesC modules in the Modules dirstdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions


    [8]ページ先頭

    ©2009-2025 Movatter.jp