I am looking for creating internal APIs for me that would generate pdfs as API call and use chalice to deploy it as serverless. So far I have code that I am stuck with 500 error that I can not debug:
from chalice import Chalice, Response
from reportlab.pdfgen import canvas
from reportlab.lib.pagesizes import letter
from reportlab.lib.pagesizes import landscape
from io import BytesIO
app = Chalice( app_name = 'printago' )
@app.route( '/' )
def index( ) :
buff = BytesIO( )
# p = canvas.Canvas( 'someName.pdf', pagesize = landscape( letter ) )
p = canvas.Canvas( buff, pagesize = landscape( letter ) )
p.setFont( 'Helvetica', 40, leading = None )
p.drawCentredString( 415, 300, 'Hallo YOU' )
p.showPage( )
p.save( )
pdf = buff.getvalue( )
buff.close( )
return Response( pdf, status_code = 200, headers = { 'Content-Type' : 'application/pdf' } )
What am I doing wrong?
I have virtual environment for this project, installed reportlab via pip in it, and after turning on debugging there is error Unable to import module
'app': No module named reportlab.pdfgen
And I was able to pass "No module" error by adding reportlab to requirments.txt file, however after this there is other error related to JSON serialization and utf-8
An error occurred during JSON serialization of response: 'utf8' codec can't decode byte 0x93 in position 10: invalid start byte
I would like to add that is working as expected when tested locally with command chalice local