在python中使用pdfcrowd时获取SyntaxError

2024-04-24 07:15:26 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试用Python 3.4学习pdfcrowd,因此我查看了他们的网站并复制了以下示例:

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))

当我尝试运行它时,出现以下错误:

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

谁能告诉我怎么修这个吗?你知道吗


Tags: andthetoclientanconvertoutputpdf