我试图使用falconrestapi提供一个pdf文件,但是我找不到任何例子。你知道吗
到目前为止,我一直在尝试:
class ReportResource:
def on_get(self, req, resp):
filename="./evaluation.pdf"
resp.downloadable_as = filename
resp.content_type = 'report/pdf'
resp.status = falcon.HTTP_200
我得到的是一个空的pdf文件,当然,我不能打开。我猜我没有在响应中加载文件内容,但我不是python方面的专家,我不知道该怎么做。你知道吗
如果我试试这个:
resp.stream, resp.stream_len = open(filename)
我得到这个错误:
UnicodeDecodeError: 'charmap' codec can't decode byte 0x8d in position 130: character maps to <undefined>
我完全肯定文件在那里。你知道吗
好了,搞定。我需要以二进制模式打开文件。我把它留在这里,以防有人需要这个例子,因为我自己找不到人。你知道吗
相关问题 更多 >
编程相关推荐