FlickrApi异常:调用photo.getSizes()时找不到照片

时间:2013-01-20 08:07:59

标签: python api flickr

我在下面的代码中遇到flickrapi.exceptions.FlickrError: Error: 1: Photo not found个异常,在此行:

sizes_element =  self.flickr.photos_getSizes(k_id = id)

然而,据我所知,我传递的photo_id是正确的。

import flickrapi

class FlickrDownloader():

def __init__(self,key,secret):
   self.api_key = key
   self.secret = secret
   self.flickr = flickrapi.FlickrAPI(self.api_key,self.secret)

def getUrls(self):
    self.photos = self.flickr
    self.urlList = []

    #get a list of photos
    photo_element = self.flickr.photos_search(tags = 'flowers',per_page = '10')
    #get and iterator over elements
    photo_iter = photo_element.iter('photo')
    self.i = 0

    for photo in photo_iter:
        #get the photo id
        id = photo.attrib['id']
        print id
        #get the different sizes of photo
        sizes_element =  self.flickr.photos_getSizes(k_id = id)
        #get an interator
        sizes_iter = sizes_element.iter('size')

        #iterate over the sizes
        for size in sizes_iter:
            #check if its original size
            if size.attrib['label'] == 'Original':
                self.urlList.append(size.attrib['source'])

    return self.urlList

1 个答案:

答案 0 :(得分:4)

flickr.photos.getSizes调用不会使用k_id参数。检查the Flickr documentation,表明您需要使用photo_id参数传递照片ID。您需要正确获取参数名称,否则Flickr不知道如何处理它们。