Skip to content

echobot example crashes because of byte encoded strings (python3)  #72

@Humphreybas

Description

@Humphreybas

Hi,
In the example echobot.py, the string to be sent is converted to bytes with .encode('utf-8') but the json.dumps() function cannot handle this. I suspect this to be a python3 issue. Can I just remove the encode() ?

 File "echobot.py", line 50, in <module>
    main()
  File "echobot.py", line 28, in main
    echo(bot)
  File "echobot.py", line 43, in echo
    bot.sendMessage(chat_id=chat_id,text=message)
  File "/usr/local/lib/python3.4/dist-packages/telegram/bot.py", line 126, in decorator
    result = func(self, *args, **kwargs)
  File "/usr/local/lib/python3.4/dist-packages/telegram/bot.py", line 158, in decorator
    result = request.post(url, data)
  File "/usr/local/lib/python3.4/dist-packages/telegram/utils/request.py", line 88, in post
    data = json.dumps(data)
  File "/usr/lib/python3.4/json/__init__.py", line 230, in dumps
    return _default_encoder.encode(obj)
  File "/usr/lib/python3.4/json/encoder.py", line 192, in encode
    chunks = self.iterencode(o, _one_shot=True)
  File "/usr/lib/python3.4/json/encoder.py", line 250, in iterencode
    return _iterencode(o, 0)
  File "/usr/lib/python3.4/json/encoder.py", line 173, in default
    raise TypeError(repr(o) + " is not JSON serializable")
TypeError: b'test' is not JSON serializable

Nice work btw!

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

    pFad - Phonifier reborn

    Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

    Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


    Alternative Proxies:

    Alternative Proxy

    pFad Proxy

    pFad v3 Proxy

    pFad v4 Proxy