Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pdfplumber.open returns AttributeError: 'bytes' object has no attribute 'encode' #117

Closed
AngusWR opened this issue May 24, 2019 · 3 comments · Fixed by #138
Closed

pdfplumber.open returns AttributeError: 'bytes' object has no attribute 'encode' #117

AngusWR opened this issue May 24, 2019 · 3 comments · Fixed by #138

Comments

@AngusWR
Copy link

AngusWR commented May 24, 2019

import pdfplumber
with pdfplumber.open("sun.pdf") as pdf:
    test = pdf.pages[0]
    print(len(test.chars))
5125
import pdfplumber
with pdfplumber.open("cba.pdf") as pdf:
    test = pdf.pages[0]
    print(len(test.chars))
Traceback (most recent call last):
  File "C:\Users\orang\Desktop\bank_interest_rate_webscraper\testing00000000.py", line
2, in <module>
    with pdfplumber.open("cba.pdf") as pdf:
  File "C:\Users\orang\AppData\Local\Programs\Python\Python36\lib\site-packages\pdfplumber\pdf.py", line 48, in open
    return cls(open(path, "rb"), **kwargs)
  File "C:\Users\orang\AppData\Local\Programs\Python\Python36\lib\site-packages\pdfplumber\pdf.py", line 28, in __init__
    self.doc = PDFDocument(PDFParser(stream), password = password)
  File "C:\Users\orang\AppData\Local\Programs\Python\Python36\lib\site-packages\pdfminer\pdfdocument.py", line 577, in __init__
    self._initialize_password(password)
  File "C:\Users\orang\AppData\Local\Programs\Python\Python36\lib\site-packages\pdfminer\pdfdocument.py", line 603, in _initialize_password
    handler = factory(docid, param, password)
  File "C:\Users\orang\AppData\Local\Programs\Python\Python36\lib\site-packages\pdfminer\pdfdocument.py", line 303, in __init__
    self.init()
  File "C:\Users\orang\AppData\Local\Programs\Python\Python36\lib\site-packages\pdfminer\pdfdocument.py", line 310, in init
    self.init_key()
  File "C:\Users\orang\AppData\Local\Programs\Python\Python36\lib\site-packages\pdfminer\pdfdocument.py", line 323, in init_key
    self.key = self.authenticate(self.password)
  File "C:\Users\orang\AppData\Local\Programs\Python\Python36\lib\site-packages\pdfminer\pdfdocument.py", line 371, in authenticate
    password = password.encode("latin1")
AttributeError: 'bytes' object has no attribute 'encode'

sun.pdf
cba.pdf

@CapAllen
Copy link

Got a same Error just now. LOL

@luoqygit
Copy link

luoqygit commented Jun 24, 2019

I had the same problem today. I solved it by adding a 'password' parameter as below:

with pdfplumber.open("cba.pdf", password="") as pdf:

@jsvine
Copy link
Owner

jsvine commented Oct 6, 2019

Fixed, merged, and pushed. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants