Ultraviolet photodesorption of molecules from icy interstellar grains can explain observations of cold gas in regions where thermal desorption is negligible. This non-thermal desorption mechanism should be especially important where UV fluxes are high. N2 and O2 are expected to play key roles in astrochemical reaction networks, both in the solid state and in the gas phase. Measurements of the wavelength-dependent photodesorption rates of these two infrared-inactive molecules provide astronomical and physical-chemical insights into the conditions required for their photodesorption. Tunable radiation from the DESIRS beamline at the SOLEIL synchrotron in the astrophysically relevant 7 to 13.6 eV range is used to irradiate pure N2 and O2 thin ice films. Photodesorption of molecules is monitored through quadrupole mass spectrometry. Absolute rates are calculated by using the well-calibrated CO photodesorption rates. Strategic N2 and O2 isotopolog mixtures are used to investigate the importance of dissociation upon irradiation. N2 photodesorption mainly occurs through excitation of the b^1Pi_u state and subsequent desorption of surface molecules. The observed vibronic structure in the N2 photodesorption spectrum, together with the absence of N3 formation, supports that the photodesorption mechanism of N2 is similar to CO, i.e., an indirect DIET (Desorption Induced by Electronic Transition) process without dissociation of the desorbing molecule. In contrast, O2 photodesorption in the 7 - 13.6 eV range occurs through dissociation and presents no vibrational structure. Photodesorption rates of N2 and O2 integrated over the far-UV field from various star-forming environments are lower than for CO. Rates vary between 10E-3 and 10E-2 photodesorbed molecules per incoming photon.