首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >单码误差PyPdf

单码误差PyPdf
EN

Stack Overflow用户
提问于 2016-06-14 22:05:03
回答 1查看 734关注 0票数 0

我尝试使用requests库下载几个pdfs,并使用pypdf将它们合并在一起。一般来说,这是很好的工作,但对于某些pdfs,我只是得到一个错误。

MWE.py

代码语言:javascript
复制
import requests
from pyPdf import PdfFileWriter, PdfFileReader
from StringIO import StringIO


input = PdfFileReader(StringIO(response.content))
input.decrypt("")
output = PdfFileWriter()
output.addPage(input.getPage(0))

outputStream = file("document-output.pdf", "wb")
output.write(outputStream)
outputStream.close()

session.close()

错误

代码语言:javascript
复制
Traceback (most recent call last):
  File "mwe.py", line 21, in <module>
    input.decrypt("")
  File "/usr/local/lib/python2.7/dist-packages/pyPdf/pdf.py", line 894, in decrypt
    return self._decrypt(password)
  File "/usr/local/lib/python2.7/dist-packages/pyPdf/pdf.py", line 904, in _decrypt
    user_password, key = self._authenticateUserPassword(password)
  File "/usr/local/lib/python2.7/dist-packages/pyPdf/pdf.py", line 945, in _authenticateUserPassword
    encrypt.get("/EncryptMetadata", BooleanObject(False)).getObject())
  File "/usr/local/lib/python2.7/dist-packages/pyPdf/pdf.py", line 1818, in _alg35
    key = _alg32(password, rev, keylen, owner_entry, p_entry, id1_entry)
  File "/usr/local/lib/python2.7/dist-packages/pyPdf/pdf.py", line 1729, in _alg32
    m.update(id1_entry)
UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-1: ordinal not in range(128)

对于跟踪,我从一个文件中读取输入,但在本例中我认为这并不重要。

我发现了一些与这个问题有关的问题,但我无法解决我的具体问题。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-06-14 22:38:07

好的,我发现这似乎是pyPdf (1.13) https://github.com/mstamy2/PyPDF2/issues/51中的一个bug

相反,使用PyPDF2 (1.26.0)可以像预期的那样工作。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/37822887

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档