Skip to content

Unicode in print_info throws codec error #1

Description

@SpareSimian
 [*] Creating backup directory: /tmp/nmap_oui_update/backups
 [*] Creating backup of nmap-mac-prefixes: nmap-mac-prefixes.20240621.072930
 [*] Downloading latest copy of OUI data from IEEE...
 [+] Downloaded to /tmp/nmap_oui_update/ieee_oui_data.txt (5800716 bytes)
 [*] Processing data: 7C3180 => SMK corporationTraceback (most recent call last):
  File "nmap_oui_update.py", line 189, in <module>
    sys.exit(main())
  File "nmap_oui_update.py", line 179, in main
    if parse_oui_file(backup_copy):
  File "nmap_oui_update.py", line 137, in parse_oui_file
    endline="\r")
  File "nmap_oui_update.py", line 54, in print_info
    sys.stdout.write(f" [{BLU}*{NC}] {msg}{endline}")
UnicodeEncodeError: 'ascii' codec can't encode character '\xa0' in position 70: ordinal not in range(128)

(I've edited out all the preceding "Processing Data" lines. With a bit of editing and using an online Unicode detector, I think the record with Unicode is just after OUI 905607.)

I haven't used Python and Unicode enough that the solution jumps out at me. This has some hints on what's going wrong:

https://stackoverflow.com/questions/9942594/unicodeencodeerror-ascii-codec-cant-encode-character-u-xa0-in-position-20

Unicode detector for pasting text from the raw file: https://freetools.textmagic.com/unicode-detector

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions