mock-server icon indicating copy to clipboard operation
mock-server copied to clipboard

Error: NameError: name 'unicode' is not defined

Open niciqy opened this issue 4 years ago • 6 comments

I am running in python 3.7. Encountering the following error when trying to create an endpoint

Uncaught exception GET /__manage (::1)
    HTTPServerRequest(protocol='http', host='localhost:8888', method='GET', uri='/__manage', version='HTTP/1.1', remote_ip='::1', headers={'Host': 'localhost:8888', 'Connection': 'keep-alive', 'Upgrade-Insecure-Requests': '1', 'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.122 Safari/537.36', 'Sec-Fetch-Dest': 'document', 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9', 'Sec-Fetch-Site': 'same-origin', 'Sec-Fetch-Mode': 'navigate', 'Sec-Fetch-User': '?1', 'Referer': 'http://localhost:8888/__manage/create?url_path=&method=GET&status_code=200&format=json', 'Accept-Encoding': 'gzip, deflate, br', 'Accept-Language': 'en-US,en;q=0.9', 'Cookie': 'csrftoken=MWWmqR1DGiHkAML7zrz1n0eoVdnlEkELXnj2PsqgbxxCZOlNCvbxzwSx3E0YGt0T; Pastease.passive.chance.kfzz9br7dC3Qwzl=1; Pastease.passive.activated.kfzz9br7dC3Qwzl=0; _ga=GA1.1.1041436616.1576026813; _xsrf=2|850e85be|11696f0fd78a46e6d9b1483a4522d35e|1583298649'})
    Traceback (most recent call last):
      File "/Users/corinel/.local/share/virtualenvs/trade-analysis-api-MP67PEe1/lib/python3.7/site-packages/tornado/web.py", line 1443, in _execute
        result = method(*self.path_args, **self.path_kwargs)
      File "/Users/corinel/.local/share/virtualenvs/trade-analysis-api-MP67PEe1/lib/python3.7/site-packages/mock_server/handlers.py", line 372, in get
        paths = resources_loader.load()
      File "/Users/corinel/.local/share/virtualenvs/trade-analysis-api-MP67PEe1/lib/python3.7/site-packages/mock_server/methodslisting.py", line 34, in load
        for item in os.walk(self.api_dir)
      File "/Users/corinel/.local/share/virtualenvs/trade-analysis-api-MP67PEe1/lib/python3.7/site-packages/mock_server/methodslisting.py", line 35, in <listcomp>
        if self._check_folder(item)]
      File "/Users/corinel/.local/share/virtualenvs/trade-analysis-api-MP67PEe1/lib/python3.7/site-packages/mock_server/methodslisting.py", line 55, in _complete_path
        url_path = UrlPath(get_url_path(item[0][len(self.api_dir):]))
      File "/Users/corinel/.local/share/virtualenvs/trade-analysis-api-MP67PEe1/lib/python3.7/site-packages/mock_server/methodslisting.py", line 107, in __init__
        self.id = slugify(self.path)
      File "/Users/corinel/.local/share/virtualenvs/trade-analysis-api-MP67PEe1/lib/python3.7/site-packages/mock_server/util.py", line 47, in slugify
        slug = unicodedata.normalize("NFKD", unicode(value)).encode("ascii", "ignore")
    NameError: name 'unicode' is not defined

Python 3 renamed the unicode type to str, the old str type has been replaced by bytes

niciqy avatar Mar 04 '20 05:03 niciqy

Hi, I am interested to use the server with python 3.7.* as well, are there any updates on this issue? Thank you.

vasiuadriana avatar Apr 09 '20 21:04 vasiuadriana

me too

yangzhijun1 avatar Apr 16 '20 10:04 yangzhijun1

Im using the same version and the error is still there.. :(

Rickbel avatar Jul 21 '20 22:07 Rickbel

Actually it seems like a bug, because even on Python 3.9 I have the same error

ilia-khaustov avatar Dec 23 '20 13:12 ilia-khaustov

Is this project nor maintained anymore? Will this issue be resolved ever?

athish-t avatar May 06 '21 21:05 athish-t

hey folks 👋 I've opened #41 that addresses this issue.

give it a look. let me know what you think. the changes therein allowed me to use this library with both the python2 and python3 interpreters.

cc @tomashanacek <-- very interested in this getting merged 🙏

withtwoemms avatar Dec 11 '22 05:12 withtwoemms