A data processing method, comprising: obtaining, a first data block, wherein the first data block is a data block obtained by dividing first optical path data; writing, padding data and the first data block into target information bits in a first data frame to form target data, wherein the target information bits are preset in the first data frame for carrying optical path data; encoding, the target data by using a first error correction encoding scheme, to obtain a first code block that has a mapping relationship with the first data frame; and sending, the first code block through an optical port, wherein before the obtaining a first data block, the method further comprises: obtaining the first optical path data; determining a length of the first data block; and dividing the first optical path data into a plurality of data blocks based on the length of the first data block, wherein the plurality of data blocks comprise the first data block, characterized in that, a length of the padding data is variable, the determining a length of the first data block comprises: determining the length of the first data block based on a preset clock frequency division ratio and a length of the first data frame, wherein the clock frequency division ratio equals an optical port rate divided by a first communications interface rate, wherein the optical port rate is a rate of an optical port through which the first code block is transmitted, the first communications interface rate is a rate of a communication interface through which the first optical path data is obtained. obtaining, a first data block, wherein the first data block is a data block obtained by dividing first optical path data; writing, padding data and the first data block into target information bits in a first data frame to form target data, wherein the target information bits are preset in the first data frame for carrying optical path data; encoding, the target data by using a first error correction encoding scheme, to obtain a first code block that has a mapping relationship with the first data frame; and sending, the first code block through an optical port, wherein before the obtaining a first data block, the method further comprises: obtaining the first optical path data; determining a length of the first data block; and dividing the first optical path data into a plurality of data blocks based on the length of the first data block, wherein the plurality of data blocks comprise the first data block, characterized in that, a length of the padding data is variable, the determining a length of the first data block comprises: determining the length of the first data block based on a preset clock frequency division ratio and a length of the first data frame, wherein the clock frequency division ratio equals an optical port rate divided by a first communications interface rate, wherein the optical port rate is a rate of an optical port through which the first code block is transmitted, the first communications interface rate is a rate of a communication interface through which the first optical path data is obtained. obtaining the first optical path data; determining a length of the first data block; and dividing the first optical path data into a plurality of data blocks based on the length of the first data block, wherein the plurality of data blocks comprise the first data block, characterized in that, a length of the padding data is variable, the determining a length of the first data block comprises: determining the length of the first data block based on a preset clock frequency division ratio and a length of the first data frame, wherein the clock frequency division ratio equals an optical port rate divided by a first communications interface rate, wherein the optical port rate is a rate of an optical port through which the first code block is transmitted, the first communications interface rate is a rate of a communication interface through which the first optical path data is obtained. determining the length of the first data block based on a preset clock frequency division ratio and a length of the first data frame, wherein the clock frequency division ratio equals an optical port rate divided by a first communications interface rate, wherein the optical port rate is a rate of an optical port through which the first code block is transmitted, the first communications interface rate is a rate of a communication interface through which the first optical path data is obtained.