In recent years, viscosity sensors have gained widespread applications. However, their high production costs and inability to achieve online measurement have limited their practical use. To overcome these limitations, we propose a novel viscosity measurement method based on optical microfiber. The sensor comprises a U-shaped optical microfiber encapsulated in a PDMS film. Under identical motion speeds in liquids with different viscosities, the optical microfiber bends to varying degrees, causing changes in the transmittance that are directly related to solution viscosity. The performance of the sensor can be adjusted by changing cantilever thickness, optical microfiber diameter, and light source wavelength. To obtain a curve that showing the relationship between transmittance and viscosity, the sensor is calibrated using solutions of known viscosity. Finally, we demonstrate the effectiveness of the method by comparing theory with experiment through testing experiments. By using this method, we achieved accurate viscosity measurements in the range of 10–50 mPa·s, with errors of all test samples less than 3.8%. Overall, this novel optical microfiber based method offers a promising solution for practical and cost-effective viscosity measurements.