From 33f46c087ec6c92dd325101169f3c5c0894d3b7c Mon Sep 17 00:00:00 2001 From: Hannes Date: Fri, 17 Jul 2020 11:50:06 +0200 Subject: [PATCH] update example for a post involving image editing Python 2 support was dropped from Twython, thanks! In Python3 we actually have to use BytesIO, see https://github.com/python-pillow/Pillow/issues/2205 --- docs/usage/advanced_usage.rst | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/docs/usage/advanced_usage.rst b/docs/usage/advanced_usage.rst index bdb0b23..df3bc48 100644 --- a/docs/usage/advanced_usage.rst +++ b/docs/usage/advanced_usage.rst @@ -59,15 +59,10 @@ with a status update. .. code-block:: python - # Assume you are working with a JPEG + # Assuming that you are working with a JPEG from PIL import Image - try: - # Python 3 - from io import StringIO - except ImportError: - # Python 2 - from StringIO import StringIO + from io import BytesIO photo = Image.open('/path/to/file/image.jpg') @@ -76,14 +71,13 @@ with a status update. height = int((float(photo.size[1]) * float(wpercent))) photo = photo.resize((basewidth, height), Image.ANTIALIAS) - image_io = StringIO.StringIO() + image_io = BytesIO() photo.save(image_io, format='JPEG') # If you do not seek(0), the image will be at the end of the file and # unable to be read image_io.seek(0) - response = twitter.upload_media(media=image_io) twitter.update_status(status='Checkout this cool image!', media_ids=[response['media_id']])