2011-04-29 2 views
0

x 대신 while (while 루프)을 사용하면 프로그램이 작동하고 누군가의 즐겨 찾기 목록에서 flickr의 첫 번째 사진을 얻습니다. 내가이 오류를왜 IndexError : list index 오류가 계속 발생합니까?

import flickrlib 
import webbrowser 
FLICKR_API_KEY = "f86203e922041a6a999fd4a59f19b1e6" 
FLICKR_API_SSECRET = "b286bcaddafb00c8" 

flickruser = raw_input("Who are you interested in? ") 
amount = int(raw_input("How many pictures would you like to see? ")) 
total = amount 
counter = 0 
imagepile = ""   
x= 0 
client = flickrlib.FlickrAgent(FLICKR_API_KEY, FLICKR_API_SSECRET) 
person = client.flickr.people.findByUsername(username= flickruser) 
userid = person[u'id'] 
photos = client.flickr.favorites.getPublicList(user_id= userid, per_page=1) 

while counter < total: 
    farm = photos[u'photo'] [x] [u'farm'] 
    server = photos[u'photo'] [x] [u'server'] 
    photo_id = photos[u'photo'] [x] [u'id'] 
    secret = photos[u'photo'] [x] [u'secret'] 
    imgsrc = "<img src='http://farm" + farm + ".static.flickr.com/" + server + "/" + photo_id + "_" + secret +".jpg' /><br />" 
    imagepile = imagepile + imgsrc 
    counter= counter+1 
    x=x+1 
htmlopen = "<html><head><title>"+ flickruser + "</title></head><body><h1>" + flickruser + "'s Public List. ""</h1>" 

simple_page = htmlopen + imagepile + "</body></html>" 

xml_file = open("webpage.html", "w") 
xml_file.write(simple_page) 
xml_file.close() 

webbrowser.open("webpage.html") 
+3

받고있는 'IndexError'의 전체 출력을 게시하십시오. – jathanism

답변

5

를 얻을 수보다 또는 첫번째 사진 이외의 나는 플리커의 API를 잘 모르겠지만, 당신은 단지 getPublicList 1 개 사진을 요청하는 것 같습니다. 어느 경우 든 totalgetPublicList에서 반환 된 사진 수보다 작은 지 확인하지 않아도됩니다.

+1

게시 후 +1 나는 당신이 먼저 거기에있어 봤어요 :) – MByD

3

여기 per_page=1 사용하기 때문에 :

photos = client.flickr.favorites.getPublicList(user_id= userid, per_page=1) 

을하고 하나 개의 사진을 얻을.

관련 문제