Using laser wavelength modulation spectroscopy (LWMS), a rapid detection method to determine the oxygen contents in glass medicine bottles with an open single path and short optical distance was proposed. It is widely acknowledged that temperature changes influence the gas line strength, the full width at half maximum (FWHM) of absorption parameters, and the density of gas molecules. As a direct consequence, these factors affect the detection accuracy of gas concentrations. Two methods of temperature compensation and correction were proposed to address this problem: one method uses a theoretical compensation of scale factors based on the relationship between various parameters in the HITRAN 2012 database (Harvard-Smithsonian Center for Astrophysics, Cambridge, MA), and the second method uses the compensation of an experimental correction function based on the relationship between temperature and harmonic intensity measurements. Furthermore, the two methods were integrated into the regression equations for the peak value of the secondary harmonics and the gas concentration for quantitative predictions. At different temperatures (ranging from 276–316 K), glass medicine bottles with oxygen concentrations of 21 % were tested to obtain predictive values based on direct concentration evaluation by the two methods. The experimental results show that the predicated root mean square errors after theoretical and experimental correction are 0.0024 and 0.0058, respectively 80.33 % and 52.46 % less than that obtained through direct concentration evaluation. This validates the effectiveness of the two proposed methods, which can further improve the accuracy and stability for detecting gas concentration using LWMS.