我在下面的代码中遇到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
答案 0 :(得分:4)
flickr.photos.getSizes调用不会使用k_id
参数。检查the Flickr documentation,表明您需要使用photo_id
参数传递照片ID。您需要正确获取参数名称,否则Flickr不知道如何处理它们。