Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8429027
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T05:13:13+00:00 2026-06-10T05:13:13+00:00

This is the first time I’ve used ReportLab, I have tried to make simple

  • 0

This is the first time I’ve used ReportLab, I have tried to make simple pdf, but I get the following error, when I try and run the script.

class ReportLabTest (webapp.RequestHandler):

    def get(self):
        c = canvas.Canvas("hello.pdf")
        c.translate(inch,inch)
        c.setFont("Helvetica", 80)
        c.setStrokeColorRGB(0.2,0.5,0.3)
        c.setFillColorRGB(1,0,1)
        c.rect(inch,inch,6*inch,9*inch, fill=1)
        c.rotate(90)
        c.setFillColorRGB(0,0,0.77)
        c.drawString(3*inch, -3*inch, "Hello World")
        c.showPage()
        c.save()
        self.write_response(c)
        self.response.headers['Content-Type'] = 'application/pdf'
        self.response.headers['Content-Disposition'] = 'filename=testpdf.pdf'

        return 

The error that I get is:

Traceback (most recent call last):
  File "/home/ducos/google_appengine/google/appengine/ext/webapp/_webapp25.py", line 710, in \__call__
        handler.get(*groups)

  File "/home/ducos/workspace/MedeticWS/www/tests.py", line 572, in get
        c.save()

  File "/home/ducos/workspace/MedeticWS/reportlab/pdfgen/canvas.py", line 1123, in save
        self._doc.SaveToFile(self._filename, self)

  File "/home/ducos/workspace/MedeticWS/reportlab/pdfbase/pdfdoc.py", line 234, in SaveToFile
        f = open(filename, "wb")

  File "/home/ducos/google_appengine/google/appengine/tools/dev_appserver_import_hook.py", line 589, in __init__
        raise IOError('invalid mode: %s' % mode)

IOError: invalid mode: wb

Thanks you for your help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T05:13:15+00:00Added an answer on June 10, 2026 at 5:13 am

    As per previous answer you can’t write to the file system. You can however provide a file like device as an argument instead of a filename. From the source of canvas You may pass a file-like object to filename as an alternative to a string.

    So you can create a StringIO object pass it to Canvas, and then rather than calling save() which may close the device (I am not sure on this – see below). do showpage() if you haven’t already and the perform getvalue() on the StringIO object to for your response.write(). e.g.

    from StringIO import StringIO
    x = StringIO()
    c = canvas.Canvas(x)
    ... dostuff
    c.save()
    output = x.getvalue()
    self.write_response(output)
    

    Just checked, if a file like handle is provided then it doesn’t call close so a save() would be fine.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

this is my first time asking a question here. I tried to be well
This is the first time I got this error. This code basically gets the
I have two update panels at my ajax page. This is first time I'm
So here I have this first time app I'm working on. When I run
this is first time i'm develope paypal form , i have problem with shipping
This is my first time working with a WPF datagrid. From what I understand
This is my first time that I use WCF and Android. So, sorry for
This is my first time using XML documents. What I'm trying to do is
This is the first time, I am involved in writing a complete client for
This is my first time playing with Active Directory, as well as the Ajax

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.