1

I am trying to get all of the member's list, everything works fine with below code but sometimes I get an error: UnicodeEncodeError: 'UCS-2' codec can't encode characters in position 11-11: Non-BMP character not supported in Tk

So how to ignore this and get members list.

server = bot.get_server(id="xxxxxxxxxxxx")
if server:
    for member in server.members:
        print('name: {}'.format(member.name) )
        print('id: {}'.format(member.id) )
Moshe Slavin
  • 5,127
  • 5
  • 23
  • 38
Demotry
  • 869
  • 4
  • 21
  • 40
  • Possible duplicate of ['UCS-2' codec can't encode characters in position 1050-1050](https://stackoverflow.com/questions/32442608/ucs-2-codec-cant-encode-characters-in-position-1050-1050) – Patrick Haugh Sep 13 '18 at 16:43
  • The problem is not in your code, IDLE can't display some of the characters. You can remove those characters, or switch to a different way of running your code. – Patrick Haugh Sep 13 '18 at 16:44

1 Answers1

1

You should use try and except.

The reason for the error is the encoding of the "members list", so try to use this:

server = bot.get_server(id="xxxxxxxxxxxx")
if server:
    for member in server.members:
        try:
            print('name: {}'.format(member.name) )
            print('id: {}'.format(member.id) )
        except UnicodeEncodeError:
            # do somthing
            pass

Hope this helps!

Moshe Slavin
  • 5,127
  • 5
  • 23
  • 38