Hi all
One of my flask route is returning 504 error out of nowhere, it was working perfectly last month.
I tried sending POST request through javascript and postman and both returns the same error.
What boggles my mind is I get a proper 200 response by running this route locally. Only difference is on my local machine I use local chromium:
browser = await p.chromium.launch()
And for Pythonanywhere:
browser = await p.chromium.launch(
executable_path="/usr/bin/chromium",
args=["--disable-gpu", "--headless"]
)
I added bunch of print statements throughout the code, and go an idea where it stops before timeout:
async def generate_pdf(html_content):
async with async_playwright() as p:
browser = await p.chromium.launch(
executable_path="/usr/bin/chromium",
args=["--disable-gpu", "--headless"]
)
page = await browser.new_page()
await page.set_content(html_content, wait_until='networkidle')
pdf_options = {
'width': '4in',
'height': '6in',
'margin': {
'right': '0.1in',
'bottom': '0.1in',
'left': '0.1in'
},
'print_background': True
}
print("log8")
try:
pdf = await page.pdf(**pdf_options)
except Exception as e:
print(f"Error generating PDF: {e}")
return Response("Error generating PDF", status=500)
await browser.close()
That log8 is the last statement I see before timeout.
Any help would be much appreciated.