If the script is working perfectly fine without headless mode, probably there is issue with the window size. Along with specifying –no-sandbox option, try changing the window size passed to the webdriver
chrome_options.add_argument(‘–window-size=1920,1080’)
This window size worked in my case.
Even if this dosen’t work you might need to add wait timers as answered before as rendering in headless mode works in a different way as compared to a browser in UI mode.
Ref for rendering in headless mode – https://www.toolsqa.com/selenium-webdriver/selenium-headless-browser-testing/