0

I get a mission to create the following GUID:

The code in Java should be like this:

GUID ==> java.util.UUID.nameUUIDFromBytes(username.getBytes());

I would like to do the same computation given a username and to receive the same GUID in Python!

I did the following but did not manage to get the same GUID:

def compute_guid_by_username(username):
    bytes = get_bytes(username)
    class NULL_NAMESPACE:
        bytes = b''

    guid = uuid.uuid3(NULL_NAMESPACE, bytes)
    return guid 

Please help.

2 Answers 2

2

I think it has something to do with the 'get_bytes' function. When I run your code without that bit, it works just fine.

Without the 'get_bytes' function:

import uuid

def generate_guid(username):
    class NULL_NAMESPACE:
        bytes = b''

    guid = uuid.uuid3(NULL_NAMESPACE, username.encode('utf-8'))
    return guid

Trying it out:

In [1]: from guids import generate_guid

In [2]: generate_guid('bob')
Out[2]: UUID('9f9d51bc-70ef-31ca-9c14-f307980a29d8')

In [3]: generate_guid('bob')
Out[3]: UUID('9f9d51bc-70ef-31ca-9c14-f307980a29d8')
Sign up to request clarification or add additional context in comments.

Comments

0

Below Code worked for me -

import uuid;

def generate_guid(username):

    class NULL_NAMESPACE:
        bytes = b''

    guid = uuid.uuid3(NULL_NAMESPACE, username);
    return guid

thanks, Murty

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.