Getting SyntaxError while using pdfcrowd with python
Question: I am trying to learn pdfcrowd with Python 3.4, so I checked out their website
and copied the following example:

    
    
    import pdfcrowd
    
    try:
        # create an API client instance
        client = pdfcrowd.Client("username", "apikey")
    
        # convert a web page and store the generated PDF into a pdf variable
        pdf = client.convertURI('http://www.google.com')
    
        # convert an HTML string and save the result to a file
        output_file = open('html.pdf', 'wb')
        html="<head></head><body>My HTML Layout</body>"
        client.convertHtml(html, output_file)
        output_file.close()
    
        # convert an HTML file
        output_file = open('file.pdf', 'wb')
        client.convertFile('/path/to/MyLayout.html', output_file)
        output_file.close()
    
    except pdfcrowd.Error, why:
        print('Failed: {}'.format(why))
    

When I try to run it, I get the following error:

    
    
    File "pf.py" line 21
       except pdfcrowd.Error, why:
                            ^
    SyntaxError: invalid syntax
    

Can anyone please tell me how to fix this?


Answer: That means to assign the error to the variable `why`. That is valid syntax in
Python2, but not in Python3. Use `except pdfcrowd.Error as why:` instead. That
is valid syntax in Python2 _and_ Python3

