Title: [FEATURE] Handle bytes input for files · Issue #2230 · python-telegram-bot/python-telegram-bot · GitHub
Open Graph Title: [FEATURE] Handle bytes input for files · Issue #2230 · python-telegram-bot/python-telegram-bot
X Title: [FEATURE] Handle bytes input for files · Issue #2230 · python-telegram-bot/python-telegram-bot
Description: Steps to reproduce Deploy the following code on Heroku: import requests import telegram bot = telegram.Bot("
Open Graph Description: Steps to reproduce Deploy the following code on Heroku: import requests import telegram bot = telegram.Bot("
X Description: Steps to reproduce Deploy the following code on Heroku: import requests import telegram bot = telegram.Bot("<TOKEN>") update = telegram.Update.de_json(request.get_json(force=True), ...
Opengraph URL: https://github.com/python-telegram-bot/python-telegram-bot/issues/2230
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[FEATURE] Handle bytes input for files","articleBody":"### Steps to reproduce\r\nDeploy the following code on Heroku:\r\n```\r\nimport requests\r\nimport telegram\r\n\r\nbot = telegram.Bot(\"\u003cTOKEN>\")\r\nupdate = telegram.Update.de_json(request.get_json(force=True), bot)\r\nchat_id = update.message.chat.id\r\nresponse = requests.get('https://source.unsplash.com/random')\r\n\r\nbot.send_photo(chat_id, response.content)\r\n```\r\n\r\n\r\n### Expected behaviour\r\nSends an image to the bot.\r\n\r\n### Actual behaviour\r\nThe app crashes.\r\n\r\n### Configuration\r\nHeroku\r\n\r\n\r\n**Version of Python, python-telegram-bot & dependencies:**\r\n```\r\n$ python -m telegram\r\npython-telegram-bot 13.1\r\ncertifi 2020.11.08\r\nPython 3.6.12 (default, Aug 18 2020, 11:10:29) [GCC 7.5.0] \r\n```\r\n\r\n### Logs\r\n```\r\nTraceback (most recent call last):\r\n File \"/app/.heroku/python/lib/python3.6/site-packages/flask/app.py\", line 2447, in wsgi_app\r\n response = self.full_dispatch_request()\r\n File \"/app/.heroku/python/lib/python3.6/site-packages/flask/app.py\", line 1952, in full_dispatch_request\r\n rv = self.handle_user_exception(e)\r\n File \"/app/.heroku/python/lib/python3.6/site-packages/flask/app.py\", line 1821, in handle_user_exception\r\n reraise(exc_type, exc_value, tb)\r\n File \"/app/.heroku/python/lib/python3.6/site-packages/flask/_compat.py\", line 39, in reraise\r\n raise value\r\n File \"/app/.heroku/python/lib/python3.6/site-packages/flask/app.py\", line 1950, in full_dispatch_request\r\n rv = self.dispatch_request()\r\n File \"/app/.heroku/python/lib/python3.6/site-packages/flask/app.py\", line 1936, in dispatch_request\r\n return self.view_functions[rule.endpoint](**req.view_args)\r\n File \"/app/app.py\", line 9, in mybot_respond\r\n return mybot.respond()\r\n File \"/app/bots/mybot.py\", line 30, in respond\r\n bot.send_photo(chat_id, response.content) \r\n File \"\u003cdecorator-gen-5>\", line 2, in send_photo\r\n File \"/app/.heroku/python/lib/python3.6/site-packages/telegram/bot.py\", line 135, in decorator\r\n result = func(*args, **kwargs)\r\n File \"/app/.heroku/python/lib/python3.6/site-packages/telegram/bot.py\", line 639, in send_photo\r\n api_kwargs=api_kwargs,\r\n File \"/app/.heroku/python/lib/python3.6/site-packages/telegram/bot.py\", line 281, in _message\r\n result = self._post(endpoint, data, timeout=timeout, api_kwargs=api_kwargs)\r\n File \"/app/.heroku/python/lib/python3.6/site-packages/telegram/bot.py\", line 245, in _post\r\n return self.request.post(f'{self.base_url}/{endpoint}', data=data, timeout=timeout)\r\n File \"/app/.heroku/python/lib/python3.6/site-packages/telegram/utils/request.py\", line 352, in post\r\n body=json.dumps(data).encode('utf-8'),\r\n File \"/app/.heroku/python/lib/python3.6/json/__init__.py\", line 231, in dumps\r\n return _default_encoder.encode(obj)\r\n File \"/app/.heroku/python/lib/python3.6/json/encoder.py\", line 199, in encode\r\n chunks = self.iterencode(o, _one_shot=True)\r\n File \"/app/.heroku/python/lib/python3.6/json/encoder.py\", line 257, in iterencode\r\n return _iterencode(o, 0)\r\n File \"/app/.heroku/python/lib/python3.6/json/encoder.py\", line 180, in default\r\n o.__class__.__name__)\r\nTypeError: Object of type 'bytes' is not JSON serializable\r\n```\r\n","author":{"url":"https://github.com/0xAhmad","@type":"Person","name":"0xAhmad"},"datePublished":"2020-12-03T06:39:30Z","url":"https://github.com/python-telegram-bot/python-telegram-bot/issues/2230"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:8d6b570c-0c35-8618-0b41-395ac4b22479 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 9ECE:6B7DC:1775859:1D9EF8E:6B026E01 |
| html-safe-nonce | d0212b72ac3ebd89b68083f6e99623dca9fab99f798487bba84fdbbf7195b2b2 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5RUNFOjZCN0RDOjE3NzU4NTk6MUQ5RUY4RTo2QjAyNkUwMSIsInZpc2l0b3JfaWQiOiIyNjM5NDg5NzgwMDk3OTA0MTMwIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 6c7d34b6248da302a80b41ee7221721aae30bd932b7dcf8099529d97ba25d33f |
| hovercard-subject-tag | issue:755914811 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python-telegram-bot/python-telegram-bot/2230/issue_layout |
| twitter:image | https://opengraph.githubassets.com/0e0bfaf2eb5aeabf587e8a6c886f4c33674d836abd9196a3c2f0501a6b5cf0d8/python-telegram-bot/python-telegram-bot/issues/2230 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/0e0bfaf2eb5aeabf587e8a6c886f4c33674d836abd9196a3c2f0501a6b5cf0d8/python-telegram-bot/python-telegram-bot/issues/2230 |
| og:image:alt | Steps to reproduce Deploy the following code on Heroku: import requests import telegram bot = telegram.Bot(" |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | 0xAhmad |
| hostname | github.com |
| expected-hostname | github.com |
| None | 87e774ee7c6b3bee0490394e4d3e57ec9dbc956f74b87ea685dc8996c1676456 |
| turbo-cache-control | no-preview |
| go-import | github.com/python-telegram-bot/python-telegram-bot git https://github.com/python-telegram-bot/python-telegram-bot.git |
| octolytics-dimension-user_id | 16178365 |
| octolytics-dimension-user_login | python-telegram-bot |
| octolytics-dimension-repository_id | 38696925 |
| octolytics-dimension-repository_nwo | python-telegram-bot/python-telegram-bot |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 38696925 |
| octolytics-dimension-repository_network_root_nwo | python-telegram-bot/python-telegram-bot |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 423dbb54c5e7bfecc838eb387c1435eb3d0e760d |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width