Flickr API: 使用Python上传图片

5

我在使用Flickr API上传图片时遇到了问题。

我使用了OAuthLib-requests库 (https://github.com/requests/requests-oauthlib)

Flickr文档: https://secure.flickr.com/services/api/upload.api.html

我的代码:

params = {
    'format'         : 'json',
    "nojsoncallback" : "1",
    'api_key'        : 'my_api_key',
}

with open('myfile.jpg', 'rb') as f:
    files = {'file': f}

    r = the_oauth_requests_session.post('https://up.flickr.com/services/upload/', params=params, files=files)
    print r.content

但是在内容中我发现了这个错误:'未指定照片'。

上传照片的方式是什么?

我已经通过身份验证,并且其他API调用都可以完美地工作(例如'flickr.photosets.create')。

提前感谢您。


为什么不使用类似flickrapi这样的工具来为您处理所有繁重的工作呢? - Ian Stapleton Cordasco
因为我需要Python 3支持 :/ - Slot
根据 https://bitbucket.org/sybren/flickrapi/issue/36/python-3-compatibility 的情况来看,这个库很快就会支持Python 3。 - Ian Stapleton Cordasco
2个回答

2
我认为Flickr不允许上传除图片和视频以外的其他文件类型。 在你的代码中:
files = {'file': f}

你确定 'file' 的类型是正确的吗?

0

解决方案非常简单:

files = {'photo': f}

改为:

files = {'file': f}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接