Flickr API: Upload an image with python

江枫思渺然 提交于 2021-02-07 07:21:30

问题


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

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

The Flickr doc: https://secure.flickr.com/services/api/upload.api.html

My code:

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 ?

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

Thank you in advance


回答1:


I think Flickr does not let you upload any other file types than images and videos. In your code:

files = {'file': f}

are you sure 'file' is of the right type?




回答2:


The solution was very simple:

files = {'photo': f}

Instead of:

files = {'file': f}


来源:https://stackoverflow.com/questions/25208309/flickr-api-upload-an-image-with-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!