question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Sending Image within Direct Message Issue (Bad Media)

See original GitHub issue

Hello! So I am unable to send images that I’m uploading within direct messages. My code is as follows: ` auth = tweepy.OAuthHandler(consumer_key, consumer_secret) auth.set_access_token(accessKey, accessSecret)

api = tweepy.API(auth)
response = api.media_upload(media)
media_id = response.media_id_string

api.send_direct_message(recipient_id=friendID, text=message, attachment_type="media", attachment_media_id=media_id)`

My media variable is a path to a .jpg file. This image is less than the maximum upload size (it uploads successfully). I get an ID associated with the image every time I attempt this process, but I always get the error: [{‘code’: 151, ‘message’: ‘There was an error sending your message: Bad Media, unable to process: Some(InvalidMedia).’} when attaching the media to a direct message.

Any suggestions would be greatly appreciated. This API Wrapper is great! Thanks for your efforts!

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:9 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
enablex3commented, Apr 13, 2021

I’m glad I could help!

On Thu, Feb 6, 2020 at 09:49 abolfazl komeazi notifications@github.com wrote:

media is the local path to a .png image on your machine or server. media_id is the id field from Twitter’s response to their image upload API. The way I got it working was using the image upload API for Twitter. The image gets uploaded and Twitter responds with the media_id. I then used that media_id and the path my local image for the media field to finally send images via direct message. … <#m_-6354165757792929527_> On Thu, Feb 6, 2020 at 6:45 AM abolfazl komeazi @.***> wrote: Hi enablex3, what are the media and media_id here? where did you upload them? — You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://nam01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Ftweepy%2Ftweepy%2Fissues%2F1278%3Femail_source%3Dnotifications%26email_token%3DAJ73YHZGUPWDW2MJEZVXVTTRBPZ4TA5CNFSM4I3QRUG2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEK65SWI%23issuecomment-582867289&data=02|01|ereyes%40mail.citadel.edu|91d3b936490a475cc62a08d7aafa0766|960c1081d06341f8844b41d738db04a3|0|0|637165863546388299&sdata=0nDYfNKYdcxs6rMR%2FKng%2F%2FNjFALedPyhKTWeT%2FQBp6Q%3D&reserved=0 https://nam01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Ftweepy%2Ftweepy%2Fissues%2F1278%3Femail_source%3Dnotifications%26email_token%3DAJ73YHZGUPWDW2MJEZVXVTTRBPZ4TA5CNFSM4I3QRUG2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEK65SWI%23issuecomment-582867289&data=02|01|ereyes%40mail.citadel.edu|a4abba05c24d406b367a08d7ab13d2e7|960c1081d06341f8844b41d738db04a3|0|0|637165973970075150&sdata=ivkFRKwJLF0EPJgY3mzAhXVeMrA9afMmKCXVsahpVIE%3D&reserved=0, or unsubscribe https://nam01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FAJ73YH6ODOASQYB2ZOSNODLRBPZ4TANCNFSM4I3QRUGQ&data=02|01|ereyes%40mail.citadel.edu|91d3b936490a475cc62a08d7aafa0766|960c1081d06341f8844b41d738db04a3|0|0|637165863546388299&sdata=33Ax03gNvLT8cgE9VsLwWMTvvhdEAQ8LKFR5f9R%2FURY%3D&reserved=0 https://nam01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FAJ73YH6ODOASQYB2ZOSNODLRBPZ4TANCNFSM4I3QRUGQ&data=02|01|ereyes%40mail.citadel.edu|a4abba05c24d406b367a08d7ab13d2e7|960c1081d06341f8844b41d738db04a3|0|0|637165973970085149&sdata=fIBrQ7HRoXtapns%2FW1TUi41evP5VC4%2FQAGiYdnifUkQ%3D&reserved=0 .

Thank you in advance. That works like a charm!

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://nam01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Ftweepy%2Ftweepy%2Fissues%2F1278%3Femail_source%3Dnotifications%26email_token%3DAJ73YH4JLIRX7KB73GLPPVTRBQPQ7A5CNFSM4I3QRUG2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEK7POVA%23issuecomment-582940500&data=02|01|ereyes%40mail.citadel.edu|a4abba05c24d406b367a08d7ab13d2e7|960c1081d06341f8844b41d738db04a3|0|0|637165973970085149&sdata=2VCqxKUsVELGpKD5x%2BcJ6uKyqWT0W8oCjNMErhKmZ6w%3D&reserved=0, or unsubscribe https://nam01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FAJ73YH3THJNO2IZI3ATIAELRBQPQ7ANCNFSM4I3QRUGQ&data=02|01|ereyes%40mail.citadel.edu|a4abba05c24d406b367a08d7ab13d2e7|960c1081d06341f8844b41d738db04a3|0|0|637165973970095140&sdata=fPYcRQpEgSiFojb4DBGkBwAuwBsjYJDvC9xcUQfuuWs%3D&reserved=0 .

1reaction
enablex3commented, Feb 6, 2020

media is the local path to a .png image on your machine or server. media_id is the id field from Twitter’s response to their image upload API.

The way I got it working was using the image upload API for Twitter. The image gets uploaded and Twitter responds with the media_id. I then used that media_id and the path my local image for the media field to finally send images via direct message.

On Thu, Feb 6, 2020 at 6:45 AM abolfazl komeazi notifications@github.com wrote:

Hi enablex3,

what are the media and media_id here? where did you upload them?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://nam01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Ftweepy%2Ftweepy%2Fissues%2F1278%3Femail_source%3Dnotifications%26email_token%3DAJ73YHZGUPWDW2MJEZVXVTTRBPZ4TA5CNFSM4I3QRUG2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEK65SWI%23issuecomment-582867289&data=02|01|ereyes%40mail.citadel.edu|91d3b936490a475cc62a08d7aafa0766|960c1081d06341f8844b41d738db04a3|0|0|637165863546388299&sdata=0nDYfNKYdcxs6rMR%2FKng%2F%2FNjFALedPyhKTWeT%2FQBp6Q%3D&reserved=0, or unsubscribe https://nam01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FAJ73YH6ODOASQYB2ZOSNODLRBPZ4TANCNFSM4I3QRUGQ&data=02|01|ereyes%40mail.citadel.edu|91d3b936490a475cc62a08d7aafa0766|960c1081d06341f8844b41d738db04a3|0|0|637165863546388299&sdata=33Ax03gNvLT8cgE9VsLwWMTvvhdEAQ8LKFR5f9R%2FURY%3D&reserved=0 .

Read more comments on GitHub >

github_iconTop Results From Across the Web

Top 5 ways to fix Android won't send picture messages problem.
Top 5 ways to fix Android won't send picture messages problem or MMS not being sent ; Step 1 – Hold the messaging...
Read more >
Instagram direct doesn't let me send photos, what can I do?
It could be some kind of bug or you're sending and uploading pics from your galleries too much.
Read more >
Some women shared the messages they get on Instagram. It's ...
Instagram DMs are regularly used to send image-based sexually abusive and pornographic content, according to the report. Users choose to send ...
Read more >
Share photos at their best quality | Popular Science
To make the most of your images, it's important to share them at their very best quality. Here's how to tweak these settings...
Read more >
Should You Send That DM? Well … - The New York Times
Even though it's common, sending a DM remains an intimate and slightly mysterious corner of social media. Here's what to keep in mind...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found