francesco
francesco

Reputation: 1

how do i post a picture with tweepy that i just saved?

im doing a twitter bot that replies people who mention him, and i need to save a file, than tweet this file, but im getting this error every time

def reply():
tweets = api.mentions_timeline(read_last_seen(FILE_NAME), tweet_mode='extended', include_entities=True)
for tweet in reversed(tweets):
    if 'invertbot1' in tweet.full_text.lower():
        image = Image.open('cat2.jpg')
        draw = ImageDraw.Draw(image)
        font = ImageFont.truetype('arial.ttf', size=17)
        text = tweet.full_text
        textwrapped = textwrap.wrap(text, width=21)
        color = 'rgb(0, 0, 0)' # black color
        draw.multiline_text((85, 30),'\n'.join(textwrapped), font=font, fill="#aa0000")
        image.save('cat1.jpg')
        print(str(tweet.id) + ' - ' + tweet.full_text)
        store_last_seen(FILE_NAME, tweet.id)
        img = 'cat1.jpg'
        import time
        api.update_status(img, "@" + tweet.user.screen_name + " Pronto", in_reply_to_status_id = tweet.id)
        os.remove('cat1.jpg')

the error i get is

tweepy.error.TweepError: Multiple values for parameter in_reply_to_status_id supplied!

Upvotes: 0

Views: 632

Answers (1)

Beppe C
Beppe C

Reputation: 13923

The image(s) is passed as array in the media_ids parameter, after a media gets uploaded:

    # upload media
    media = api.media_upload(filename='cat1.jpg')
    # reply
    api.update_status(status='my reply', in_reply_to_status_id=tweet.id, media_ids=[media.media_id])

Note to reply the author of the Tweet must mentioned within the status text, otherwise in_reply_to_status_id is ignored. See documentation of update_status

Upvotes: 2

Related Questions