From 181c594a3b2fe3d546e58c253ffcebd80bd81f47 Mon Sep 17 00:00:00 2001 From: Harmon Date: Thu, 14 Jan 2021 05:36:20 -0600 Subject: [PATCH] Improve API.update_profile_banner file uploading Use files parameter of requests Session.request Allow Twitter's API to respond with 413 HTTP status code and "media type unrecognized." errors instead of checking for file size and type prior to upload. The previous max file size restriction of 700 KiB seems to have been significantly overly restrictive regardless. --- tweepy/api.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/tweepy/api.py b/tweepy/api.py index 47289e9..0fbd77b 100644 --- a/tweepy/api.py +++ b/tweepy/api.py @@ -819,15 +819,17 @@ class API: """ :reference: https://developer.twitter.com/en/docs/accounts-and-users/manage-account-settings/api-reference/post-account-update_profile_banner :allowed_param: 'width', 'height', 'offset_left', 'offset_right' """ - headers, post_data = API._pack_image(filename, 700, - form_field='banner', f=file) + if file is not None: + files = {'banner': (filename, file)} + else: + files = {'banner': open(filename, 'rb')} return bind_api( api=self, path='/account/update_profile_banner.json', method='POST', allowed_param=['width', 'height', 'offset_left', 'offset_right'], require_auth=True - )(post_data=post_data, headers=headers) + )(files=files) @property def update_profile(self): -- 2.25.1