2

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
4

1 回答 1

4

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

于 2013-06-02T08:05:00.323 回答