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 #124

Closed
leocaza opened this issue Apr 28, 2017 · 5 comments
Closed

NameError: name 'unicode' is not defined #124

leocaza opened this issue Apr 28, 2017 · 5 comments
Assignees

Comments

@leocaza
Copy link

leocaza commented Apr 28, 2017

Hi,

Perhaps you will be able to help me.

I downloaded the "tldextract" in order to run "newspaper" (https://github.com/codelucas/newspaper), but I'm getting an error message "NameError: name 'unicode' is not defined". Why is unicode not defined, I can see "unicode = str" in the remote.py file.

After running this :

  import newspaper

  cnn_paper = newspaper.build('http://www.fox13now.com')
  

This error message appear :

File "C:\anaconda3\lib\tldextract\remote.py", line 56, in _decode_utf8
   if not isinstance(text, unicode):
**NameError: name 'unicode' is not defined**
In remote.py (from tldextract) :

This part seem to be the problem :

d```
ef _decode_utf8(text):
""" Decode from utf8 to Python unicode string.
The suffix list, wherever its origin, should be UTF-8 encoded.
"""
if not isinstance(text, unicode):
return unicode(text, 'utf-8')
else:
return text


Do you understand where the error came from?
@john-kurkowski
Copy link
Owner

It should be defined for Python 3 on this line. What version of Python are you using? Maybe we need a more robust version check.

@leocaza
Copy link
Author

leocaza commented Apr 28, 2017

Python 3.6.0 |Continuum Analytics, Inc.| (default, Dec 23 2016, 11:57:41) [MSC v.1900 64 bit (AMD64)] on win32

@john-kurkowski
Copy link
Owner

I can't reproduce on

Python 3.6.0 (default, Apr 28 2017, 17:32:58)
[GCC 4.2.1 Compatible Apple LLVM 8.1.0 (clang-802.0.42)] on darwin

Maybe you have a copy of Python 2's urlparse installed in your Python 3.6.0? That would trick this version check. I think this warrants a more direct sys.version_info check, instead of try/except ImportError. Pythonistas love EAFP but yeesh it's indirect and unintuitive in this case.

@leocaza
Copy link
Author

leocaza commented Apr 29, 2017

You are a genius. Thanks mate

@leocaza leocaza closed this as completed Apr 29, 2017
@john-kurkowski
Copy link
Owner

Glad that worked around the issue for you! I'ma keep this open. The clever EAFP Python version check has overstayed it's welcome. Don't want it to bite someone again.

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

No branches or pull requests

2 participants