Search code examples
python-3.xpython-requestsflickrurllib3

Python flickrapi search.photos returns the same picture on every page


I'm testing the flickrapi for python and have some code that randomly chooses a picture of Chinese food. It does this by getting 1 result on 1 page and using the total number of pages in that result to choose 1 result on 1 random page. Here is the code I'm using to get the images:

flickr = flickrapi.FlickrAPI(api_key='mykey', secret='mysecret', format='parsed-json', cache=False)
data1 = flickr.photos.search(tags='Chinese Food',
                            page=1,
                            per_page=1,
                            tag_mode='all',
                            media='photos',
                            content_type=1)

data2 = flickr.photos.search(tags='Chinese Food',
                            page=randint(1, data1['photos']['pages']),
                            per_page=1,
                            tag_mode='all',
                            media='photos',
                            content_type=1,
                            extras='url_l')

No matter what I do the result in data2 is always the exact same image returned in data1, I could get the first result from page 1 and the first result from page 3472 and the image is exactly the same every time.

Here is a sample of the data returned

//From data1
{'photos': {'page': 1, 'pages': 70007, 'perpage': 1, 'total': '70007', 'photo': [{'id': '35800805325', 'owner': '24171591@N06', 'secret': '408928a034', 'server': '4261', 'farm': 5, 'title': 'Personalized Maple Wood Chopsticks', 'ispublic': 1, 'isfriend': 0, 'isfamily': 0}]}, 'stat': 'ok'}

//From data2
{'photos': {'page': 41043, 'pages': 70007, 'perpage': 1, 'total': '70007', 'photo': [{'id': '35800805325', 'owner': '24171591@N06', 'secret': '408928a034', 'server': '4261', 'farm': 5, 'title': 'Personalized Maple Wood Chopsticks', 'ispublic': 1, 'isfriend': 0, 'isfamily': 0, 'url_l': 'https://farm5.staticflickr.com/4261/35800805325_408928a034_b.jpg', 'height_l': '859', 'width_l': '1024'}]}, 'stat': 'ok'}

Notice the id and title in both sets of data are exactly the same and the page numbers are different. I've tested this in the Flickr API explorer with the exact same parameters and I do get the same image when I specify page 1 but I also get a completely different image if I specify any other page, so this seems to be an issue with the python flickrapi implementation or one of its dependencies maybe?

I can't seem to find the issue. What is going on?


Solution

  • Looks like other people have been having this issue with Flickr's API since 2011 and it still hasn't been fixed. So, it doesn't seem to be related to Python or the Python Flickr module. I was able to improve the "randomness" by increasing the number of results per page which is something I didn't want to do but it's the only thing that works.