Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UnicodeEncodeError with char '\u0361' #61

Closed
Naught0 opened this issue Oct 26, 2017 · 4 comments
Closed

UnicodeEncodeError with char '\u0361' #61

Naught0 opened this issue Oct 26, 2017 · 4 comments
Labels

Comments

@Naught0
Copy link

Naught0 commented Oct 26, 2017

Here is the setup of the main client

self.redis_client = aredis.StrictRedis(host='localhost', decode_responses=True)

This is the statement which the error surrounds.

await self.redis_client.set(f'memecache:{f_search}', f'{link}', ex=86400)

The URL in question is:
http://knowyourmeme.com/memes/hentai-woody-%E5%A4%89%E6%85%8B%E3%82%A6%E3%83%83%E3%83%87%E3%82%A3%E3%83%BC
(the URL is a result of searching the site for the Buzz Lightyear meme and accidentally coming across this which happened to introduce a bug).

Full traceback:

Ignoring exception in command meme:
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/dist-packages/discord/ext/commands/core.py", line 62, in wrapped
    ret = yield from coro(*args, **kwargs)
  File "/root/qtbot/cogs/meme.py", line 42, in get_meme_info
    await self.redis_client.set(f'memecache:{f_search}', f'{link}', ex=86400)
  File "/usr/local/lib/python3.6/dist-packages/aredis/commands/strings.py", line 270, in set
    return await self.execute_command('SET', *pieces)
  File "/usr/local/lib/python3.6/dist-packages/aredis/client.py", line 163, in execute_command
    await connection.send_command(*args)
  File "/usr/local/lib/python3.6/dist-packages/aredis/connection.py", line 463, in send_command
    await self.send_packed_command(self.pack_command(*args))
  File "/usr/local/lib/python3.6/dist-packages/aredis/connection.py", line 514, in pack_command
    SYM_CRLF, b(arg), SYM_CRLF))
  File "/usr/local/lib/python3.6/dist-packages/aredis/utils.py", line 8, in b
    return x.encode('latin-1') if not isinstance(x, bytes) else x
UnicodeEncodeError: 'latin-1' codec can't encode character '\u0361' in position 30: ordinal not in range(256)

tmux is weird about scrolling in my TTY, so hopefully that traceback is coherent enough.

@NoneGG
Copy link
Owner

NoneGG commented Oct 26, 2017

Don't worry, I will check about that

@NoneGG
Copy link
Owner

NoneGG commented Oct 26, 2017

@Naught0
Decode bug is fixed and tested with code like below:

client = StrictRedis(host='127.0.0.1', port=6379, db=0, decode_responses=True)
link = '\u0251'
f_search = 'BuzzLightyear'
await client.set(f'memecache:{f_search}', f'{link}')
await client.get(f'memecache:{f_search}')

If you don't mind, could you try it with command:
pip install git+https://github.com/NoneGG/aredis

@Naught0
Copy link
Author

Naught0 commented Oct 26, 2017

Sorry, I've been out! Thanks for the prompt reply. I will test the git version immediately and report back.

@Naught0
Copy link
Author

Naught0 commented Oct 26, 2017

Would you look at that, it worked like a charm. Thanks again for the fix!

@Naught0 Naught0 closed this as completed Oct 26, 2017
@NoneGG NoneGG added the bug label Nov 19, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants