NameError: name 'unicode' is not defined -- bench setup lets-encrypt

Hi there,

I tried installing v12 from scratch, and when trying to do this:

sudo -H bench setup lets-encrypt site1.local --custom-domain mydomain.com

File “/home/ry/.bench/bench/config/nginx.py”, line 217, in get_sites_with_config
if isinstance(domain, str) or isinstance(domain, unicode):
NameError: name ‘unicode’ is not defined

Please advise, thanks!

I am also getting the same error

I solved this by editing nginx.py in .bench/bench/config and replacing the following line in 217

if isinstance(domain, str) or isinstance(domain, unicode):

with

if isinstance(domain, str) or isinstance(domain, bytes):

3 Likes

Hi Vinod,

Many thanks for posting this, I will try on my end.

If you don’t mind me asking, did you do a clean install? Did you use the easy install?

Thanks!

easy install

the error has nothing to do with the install kind i suppose though !! you may try replacing with ‘str’ too to see if it works …

1 Like

Thanks! I’ll have to wait for 7 more days as I made too many requests in let’s encrypt

If, like me, you are shell scripting your installation and want to automate patching nginx.py you can do what I do:

cd ${HOME}/.bench/bench/config;                   # Got to bench config directory
cp nginx.py nginx_BACKUP.py;                      # Back up your config file

# Set variables
declare PATTERN="isinstance(domain, unicode)";
declare REPLACEMENT="\t\t\t\tif isinstance(domain, str) or isinstance(domain, bytes):";
#
cat nginx.py | grep "isinstance";                 # Get a 'before' view
sed -i "/${PATTERN}/c\\${REPLACEMENT}" nginx.py;  # Do the replacement
cat nginx.py | grep "isinstance";                 # Get an 'after' view

You ought to see the following:

erpnext@mine:~$ cd ${HOME}/.bench/bench/config;
erpnext@mine:~/.bench/bench/config$ cp nginx.py nginx_BACKUP.py;
erpnext@mine:~/.bench/bench/config$ declare PATTERN="isinstance(domain, unicode)";
erpnext@mine:~/.bench/bench/config$ declare REPLACEMENT="                                if isinstance(domain, str) or isinstance(domain, bytes):";
erpnext@mine:~/.bench/bench/config$ cat nginx.py | grep "isinstance";
				    if isinstance(domain, str) or isinstance(domain, unicode):
erpnext@mine:~/.bench/bench/config$ sed -i "/${PATTERN}/c\ ${REPLACEMENT}" nginx.py;
erpnext@mine:~/.bench/bench/config$ cat nginx.py | grep "isinstance";
                    if isinstance(domain, str) or isinstance(domain, bytes):
erpnext@mine:~/.bench/bench/config$ 

btw – Kudos goes to @Vinob_chander_Ramasw for solving the original issue!!