[PYTHON] Successful update_with_media with twitter API

I used this this time

For Python 3.x

If you want to do ʻupdate_with_media () in Python 3.x, you need to modify ʻapi.py as follows.

 bod.append('Content-Disposition: form-data; name="%s"' % mediafield)
+ bod.append('Content-Transfer-Encoding: base64')

- body = '\r\n'.join(bod)
+ body = '\r\n'.join(bod).encode('utf-8')

https://github.com/sixohsix/twitter/issues/233

Also, if you are decoding the file with base64 when posting, you need to do something like data = base64.b64encode (f.read ()). Decode ("utf8", "ignore") It may not be necessary if it is a normal image # Unconfirmed

Parameters when posting

When posting only a message, I could do it with keyword arguments, but when I did the same with ʻupdate_with_media ()`, I got an error. In this case I had to pass it as a dictionary

params = {"media[]": data,
	      "status": msg
	     }
tw.statuses.update_with_media(**params)

Recommended Posts

Successful update_with_media with twitter API
Support yourself with Twitter API
Specifying the date with the Twitter API
Collecting information from Twitter with Python (Twitter API)
Post from another account with Twitter API
Extract sudden buzzwords with twitter streaming API
Tweet regularly with the Go language Twitter API
Twitter OAuth with Django
Extrude with Fusion360 API
Hit the Twitter API after Oauth authentication with Django
[Life hack] Women's Anna support bot with Twitter API
Pick up only crispy Japanese with Twitter streaming API
Image download with Flickr API
Try hitting the Twitter API quickly and easily with Python
Use Trello API with python
Create an API with Django
Twitter graphing memo with Python
Extract Twitter data with CSV
Try using the Twitter API
I tried follow management with Twitter API and Python (easy)
Get information with zabbix api
Streamline information gathering with the Twitter API and Slack bots
Try using the Twitter API
Play RocketChat with API / Python
Call the API with python3.
Search twitter tweets with python
Use subsonic API with python3
Qiita API Oauth with Django
Get ranking with Rakuten API
Crawling with Python and Twitter API 2-Implementation of user search function
I made a Twitter Bot with Go x Qiita API x Lambda
Operate Nutanix with REST API Part 2
[AWS] Create API with API Gateway + Lambda
Get reviews with python googlemap api
Run Rotrics DexArm with python API
Persist Flask API server with forever
Quine Post with Qiita API (Python)
Twitter posting application made with Django
Hit the Etherpad-lite API with Python
Detect video objects with Video Intelligence API
Create API using hug with mod_wsgi
Easily post to twitter with Python 3
Continuous acquisition by Twitter API (Tips)
GraphQL API with graphene_django in Django
Twitter search client made with bottle
Introducing Google Map API with rails
[Memo] Tweet on twitter with python
Hit ISE's ERS API with PowerShell
I tried to delete bad tweets regularly with AWS Lambda + Twitter API
Create a Twitter BOT service with GAE / P + Tweepy + RIOT API! (Part 2)
Try collecting sites all over Japan compatible with Brave browser with Twitter API
Be careful when retrieving tweets at regular intervals with the Twitter API