2

From the database

Id EndpointId  MacAddress  IsDefault   IsAuto

16 -2147483641 0x08002781A502 1 1 20 -2147483639 0x005056A54212 1 1

MacAddress column is BINARY(6) datatype

I'm using FreeTDS with Python and SQLAlchemy to get the data.

mymetadata = MetaData(engine_idf)

macadds = Table('EndpointsMacs',mymetadata,schema='dbo',autoload=True)

for row in macadds.select(macadds.c.IsDefault == 1).execute():
    print row

What I get back is.

(16, -2147483641, "\x08\x00'\x81\xa5\x02", True, True)

(20, -2147483639, '\x00PV\xa5B\x12', True, True)

I need to get the third value in the text equivalent so that I can work with the actual value of 08002781A502

Thanks

1 Answer 1

1

You can use binascii.hexlify (or binascii.h2a_hex) to get hexadecimal representation:

>>> import binascii
>>> binascii.hexlify("\x08\x00'\x81\xa5\x02")
'08002781a502'

and binascii.unhexlify in case you want to get binary data representation:

Sign up to request clarification or add additional context in comments.

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.