New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Using updateStatusWithMedia with in-memory image data #191
Comments
You can do t.post(URL, params={'status': message}, files={'file': open('report.jpg', 'rb')}) That should work! Sent from my iPhone On May 6, 2013, at 3:35 PM, Daniel Shapiro notifications@github.com wrote:
|
@michaelhelmick in that case isn't |
Can you put the bytes into a StringIO? from PIL import Image Or do you absolutely only need to pass bytes? There might be a way. But I'm driving and hard to look it up right now haha Sent from my iPhone On May 6, 2013, at 3:45 PM, Daniel Shapiro notifications@github.com wrote:
|
@michaelhelmick hmm, when I pass a PIL Image like you suggested above, it fails when |
As in you've tried... from StringIO import StringIO
from twython import Twython
t = Twython(...)
t.post(URL, params = {'status': message}, files={'file': StringIO(...)}) |
@ryanmcgrath Yes sir.
This is Twython 2.9.1, requests 1.2.0, and requests-oauthlib 0.3.1 |
Hmmm, the following seems to post successfully for me (e.g, no 403, etc). Try this perhaps? from StringIO import StringIO
t.post('/statuses/update', params = {'status': 'Testing'}, files = {
'file': StringIO(open('sidebar_pic.png').read())
}) |
Ah, hold, I see the issue. |
Here we go, this should do what you want. Just worked for me. from StringIO import StringIO
from twython import Twython
t = Twython(...)
img = open('img_url').read()
t.post('/statuses/update_with_media', params = {'status': 'Testing New Status'}, files = {
'media': StringIO(img)
# 'media': ('OrThisIfYouWantToNameTheFile.lol', StringIO(img))
}) There's a larger question of whether we should have this native in the library, but... I wanna sleep on that one I think. |
This above works great - thank you! |
Nice! I'm going to close this for now, but we might want to look at trying to detect if a StringIO object is passed to the media status update method in the future. Let us know if you notice anything else! |
If you take a look at my "requests-Facebook" library, @ryanmcgrath, I am doing something pretty cool. I'm allowing the user to pass bytes (I think off the top of my head) so they can edit the image and whatnot before hand. In the readme there is an example of how to resize an image then post it to Facebook Sent from my iPhone On May 6, 2013, at 5:59 PM, Ryan McGrath notifications@github.com wrote:
|
I mean, that same thing can be accomplished by... editing the image beforehand, then passing it in via StringIO, no? |
I think that's what I'm doing in the lib. I'd have to see. Haven't touched in a couple months Sent from my iPhone On May 6, 2013, at 7:53 PM, Ryan McGrath notifications@github.com wrote:
|
Back in 2.7, I could make the following call:
But the internal
_media_update
function has since been removed, so I can't upgrade Twython. Any chance it could come back or some other solution for posting in-memory image data could be added?Or perhaps I'm missing something and there's a way to do this with the latest Twython?
Thanks!
The text was updated successfully, but these errors were encountered: