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

NameError: name 'unicode' is not defined (line 2760 in 'fitz.py') #466

Closed
jaredRSEC opened this issue Mar 17, 2020 · 5 comments
Closed

NameError: name 'unicode' is not defined (line 2760 in 'fitz.py') #466

jaredRSEC opened this issue Mar 17, 2020 · 5 comments
Assignees
Labels

Comments

@jaredRSEC
Copy link

jaredRSEC commented Mar 17, 2020

Please provide all mandatory information!

Describe the bug (mandatory)

line 2760 in 'fitz.py': (in 'save' function)
elif type(filename) == unicode:
NameError: name 'unicode' is not defined

To Reproduce (mandatory)

doc = fitz.open()
doc.newPage()
doc.save('save_test.pdf')

Expected behavior (optional)

Should save the file without error.

Screenshots (optional)

Your configuration (mandatory)

Windows 10 64-bit
Python 3.7.2 64-bit
PyMuPDF 1.16.13

Additional context (optional)

Fixed by adding from past.builtins import unicode to top of 'fitz.py'.

@JorjMcKie
Copy link
Collaborator

Sorry, cannot reproduce this error.
Your snippet works fine with me for all Python versions .
Also, the referenced line should never be executed in Python 3 ... but I will consider to make sure that it ever will only be used for Python 2.

@JorjMcKie
Copy link
Collaborator

The next version will have the following change in behavior:
If filename is not str then a Python 2 check is made and then typeunicode is checked. If that fails, str(filename) is used and a potential exception accepted at that point.

This avoids more imports and still supports filenames provided as pathlib.Path.

@JorjMcKie
Copy link
Collaborator

New version 1.16.14 is on PyPI.

@cbm755
Copy link
Contributor

cbm755 commented Mar 27, 2020

On 1.16.11, I could hit something like using pathlib.

from pathlib import Path
p = Path('hello.pdf')

then

doc = fitz.open() 
doc.newPage()                                                                                  
doc.save(p)

       ~/.local/lib/python3.7/site-packages/fitz/fitz.py in save(self, filename, garbage, clean, deflate, incremental, ascii, expand, linear, pretty, encryption, permissions, owner_pw, user_pw)
   2673         if type(filename) == str:
   2674             pass
-> 2675         elif type(filename) == unicode:
   2676             filename = filename.encode('utf8')
   2677         else:

NameError: name 'unicode' is not defined
>>> fitz.version                                                                                   
('1.16.11', '1.16.0', '20200221154027')

But upgrading to 1.16.14 fixed it for me.

@JorjMcKie
Copy link
Collaborator

@cbm755 - thank your for the feedback!

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

No branches or pull requests

3 participants