Ich möchte ein Bild auf einem Modell ImageField
gespeichert twittern. Ich benutze tweepy
, aber ich bin offen für alles, was funktioniert.Django. Tweet Bild gespeichert auf ImageField
Dies ist, was ich versucht habe:
Erstens:
api = tweepy.API(auth)
api.update_with_media(filename=model_object.image.name, status=text, file=model_object.image)
error: TweepError: Invalid file type for image: None
Dann:
from PIL import Image
api = tweepy.API(auth)
image_file = Image.open(model_object.image)
api.update_with_media(filename=model_object.image.name, status=text, file=image_file)
219, in update_with_media headers, post_data = API._pack_image(filename, 3072, form_field='media[]', f=f) File "/home/alejandro/Proyectos/criptohisoka/local/lib/python2.7/site-packages/tweepy/api.py", line 1311, in _pack_image f.seek(0, 2) # Seek to end of file TypeError: seek() takes exactly 2 arguments (3 given)
Endlich:
from PIL import Image
from StringIO import StringIO
api = tweepy.API(auth)
image_file = Image.open(model_object.image)
stringio_obj = StringIO()
image_file.save(stringio_obj, format="JPEG")
api.update_with_media(filename=model_object.image.name, status=text, file=stringio_obj)
TweepError: Invalid file type for image: None
Ich bin mir nicht sicher, was die update_with_media
Methode als Datei erwartet. Hier ist der relevante tweepy
source code und hier sind die docs.
Es sieht aus wie es für ein File-Objekt suchen, so dass Ihr zweites Beispiel sollte funktionieren. Können Sie den StackTrace mit TypeError erweitern? Es sieht so aus, als ob das Problem nicht beim tatsächlichen Anruf liegt. – lonewaft
veraltet https://dev.twitter.com/rest/reference/post/statuses/update_with_media – slackmart
@lonewaft Habe gerade noch ein paar Tracebacks hinzugefügt ... aber es gibt nicht viel hinzuzufügen. Sieht für mich wie ein Käfer aus. – alejoss