1

Tumblpy ライブラリを使った API を使って Tumblr に動画を移植したいと思っていました。

私のコードはこれです:

import requests
r = requests.get(video-url)
f = {'data':r.content}
dat = urllib.urlencode(f)


t.post('post', blog_url='http://tumblrname.tumblr.com/',params={'type':'video', 
            'title':post.title, 'slug': post.slug,'date':post.date,'data':dat,'tags':post.tagscsv,
                'caption': post.body_html}) #t is TumblPy instance

まあ、私はこれで成功していません。確かではありませんが、投稿を成功させるためにバイナリコンテンツをエンコードする方法を見逃していると思います。

4

1 に答える 1

1

おそらく、写真を投稿する方法と同様になるでしょう。この場合、ライブラリはファイル(のような)オブジェクトを必要とします。応答requestsは、ファイルのようなオブジェクトとして問題なく機能します。

import requests
r = requests.get(video_url)

t.post('post', blog_url='http://tumblrname.tumblr.com/', 
    params={'type': 'video', 'title': post.title, 'slug': post.slug, 
            'date': post.date, 'data': r.raw, 'tags': post.tagscsv,
            'caption': post.body_html})

wherer.rawは、ファイルのようなオブジェクトを提供します。このオブジェクトを読み取ると、 から読み取ったビデオ データが得られますvideo_url

于 2013-02-20T15:02:02.417 に答える