unicode "Device type" #286

Closed
opened 2025-12-29 16:20:32 +01:00 by adam · 2 comments
Owner

Originally created by @milentrifonov on GitHub (Jul 25, 2016).

Adding non ascii character in "Device type" field causes the exception:
<type 'exceptions.UnicodeEncodeError'>
'ascii' codec can't encode character u'\u042f' in position 0: ordinal not in range(128)

Not sure if this is intentional or not to use only ascii symbol for "Device type" name, but after this this record is unusable and cannot be deleted.
Steps to reproduce:

  1. Go to "Device Types" -> "+Add a device type"
  2. For device Model type something in cyrillic letters
  3. Click "Create"
  4. You get the error:
    type 'exceptions.UnicodeEncodeError'
    'ascii' codec can't encode character u'\u042f' in position 0: ordinal not in range(128)
Originally created by @milentrifonov on GitHub (Jul 25, 2016). Adding non ascii character in "Device type" field causes the exception: <type 'exceptions.UnicodeEncodeError'> 'ascii' codec can't encode character u'\u042f' in position 0: ordinal not in range(128) Not sure if this is intentional or not to use only ascii symbol for "Device type" name, but after this this record is unusable and cannot be deleted. Steps to reproduce: 1. Go to "Device Types" -> "+Add a device type" 2. For device Model type something in cyrillic letters 3. Click "Create" 4. You get the error: type 'exceptions.UnicodeEncodeError' 'ascii' codec can't encode character u'\u042f' in position 0: ordinal not in range(128)
adam closed this issue 2025-12-29 16:20:32 +01:00
Author
Owner

@milentrifonov commented on GitHub (Jul 25, 2016):

After some debugging I found that this is due to handling nonunicode strings in some python functions. Like print formating in examle:
here in netbox/dcim/models.py on line 407 if I change:
def unicode(self):
return "{} {}".format(self.manufacturer, self.model)

to

def __unicode__(self):
    return u"{} {}".format(self.manufacturer, self.model)

it works without exception.

As a workaround I decided to put
from future import unicode_literals
in the beginning of all (or most) python files in the applicatin

@milentrifonov commented on GitHub (Jul 25, 2016): After some debugging I found that this is due to handling nonunicode strings in some python functions. Like print formating in examle: here in netbox/dcim/models.py on line 407 if I change: def **unicode**(self): return "{} {}".format(self.manufacturer, self.model) to ``` def __unicode__(self): return u"{} {}".format(self.manufacturer, self.model) ``` it works without exception. As a workaround I decided to put from **future** import unicode_literals in the beginning of all (or most) python files in the applicatin
Author
Owner

@jeremystretch commented on GitHub (Jul 25, 2016):

This was fixed in v1.3.1. Please upgrade to the latest code.

@jeremystretch commented on GitHub (Jul 25, 2016): This was fixed in v1.3.1. Please upgrade to the latest code.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#286