尝试从库运行示例时发生pyPDF2类型错误

2024-04-26 00:03:56 发布

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

从这里得到pyPDF2库: https://github.com/mstamy2/PyPDF2/tree/Python3-3

当尝试运行脚本“示例1:”时,请从那里查看:

PyPDF2 python versions (2.5 - 3.3) compatibility branch

Traceback (most recent call last):

  File "1.py", line 6, in <module>
    input1 = PdfFileReader(open("document1.pdf", "rb"))
  File "C:\Python33\lib\site-packages\PyPDF2\pdf.py", line 595, in __init__
    self.read(stream)
  File "C:\Python33\lib\site-packages\PyPDF2\pdf.py", line 1097, in read
    streamData = StringIO(xrefstream.getData())
TypeError: initial_value must be str or None, not bytes

怎么了?在


Tags: inpyhttpsgithubcomreadpdflib
1条回答
网友
1楼 · 发布于 2024-04-26 00:03:56

这是一个与PyPDF2和python3的兼容性有关的问题。在

在我的情况下,我通过替换pdf.py文件以及实用工具.py在这里可以找到它们,它们基本上控制您是否运行python3,如果您运行的是python3,则以字节而不是字符串的形式接收数据。在

相关问题 更多 >