CO2 in the sample is a big PITA when it comes to measurement. I doesn't change the density of the solution appreciably but it screws up the reading by coming out of solution and, with a hydrometer, clinging to the side of the instrument buoying it up (making it read too high) or, in the case of a pycnometer or U-tube meter displacing liquid so that the bottle or tube contain less liquid and reads too low.
When using a hydrometer I put the sample in a cylinder, put my hand over the top and shake like mad. I then fill a second cylinder with the shaken beer (it's possible to pour off the liquid and leave the foam behind) to near the top. When the hydrometer is dropped in it causes the second cylinder to overflow carrying any remaining foam away. After the hydrometer settles, I give it a spin to dislodge any bubbles that may be adhering. This seems to work pretty well.
With a U-tube meter I suck the beer into a syringe, close the tip and shake like mad while drawing the plunger back. I then open the tip and expel the gas that was released. A few cycles of this and the beer is degassed. Anton Paar recommends feeding their instruments from a syringe, blocking the outlet of the instrument and pushing on the plunger while the measurement is being taken. The pressure holds the gas in solution. I have to believe this stiffens the U-tube (think of what happens when you blow into a balloon) but perhaps this doesn't make an appreciable difference.