Get Hex triplet for color and real 256 RGB from diffuse Color using python
This code adapted from devtalk.blender.org, convert color from blender standard active material to hex.

import bpy

#code by : brecht - devtalk.blender.org
def to_hex(c):
    if c &lt; 0.0031308:
        srgb = 0.0 if c &lt; 0.0 else c * 12.92
    else:
        srgb = 1.055 * math.pow(c, 1.0 / 2.4) - 0.055

    return hex(max(min(int(srgb * 255 + 0.5), 255), 0))

def toHex(r,g,b):
    rgb = [r,g,b]
    result = ""
    i=0
    while i &lt; 3:
        val = str(to_hex(rgb[i]))
        val = val[2:]
        if len(val) == 1:
            val += val
        result+=val
        i+=1
    return result

ob = bpy.context.object
color_inferior = ob.active_material.diffuse_color

a = toHex(color_inferior[0],color_inferior[1],color_inferior[2])

print (a)