Flickr API:使用python上传图像 [英] Flickr API: Upload an image with python

查看:91
本文介绍了Flickr API:使用python上传图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

上传通过Flickr API的图片时遇到问题.

I have a problem to upload an image trought the Flickr API.

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

I use OAuthLib-requests (https://github.com/requests/requests-oauthlib)

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

The Flickr doc: 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

但是在内容中我会发现以下错误:未指定照片".

But in the content I can find this error: 'No photo specified'.

上传照片的方式是什么?

What is the way to upload a photo ?

我已通过身份验证,其他api调用也可以正常工作(例如'flickr.photosets.create')

I'm authenticated, and others api calls work perfectly (like 'flickr.photosets.create')

提前谢谢

推荐答案

解决方案非常简单:

files = {'photo': f}

代替:

files = {'file': f}

这篇关于Flickr API:使用python上传图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆