obj.closest_point_on_mesh ValueError: too many values to unpack
Look at the documentation of closest_point_on_mesh: https://docs.blender.org/api/2.79/bpy.types.Object.html#bpy.types.Object.closest_point_on_mesh

Return (result, location, normal, index):

result, boolean
location, The location on the object closest to the point, float array of 3 items in [-inf, inf]
normal, The face normal at the closest point, float array of 3 items in [-inf, inf]
index, The face index, -1 when original data isn’t available, int in [-inf, inf]


So the function is returning 4 values, but you only unpack 3.
It should be called like this:
result, point, normal, face = obj.closest_point_on_mesh(p, max_dist)