N
N
nosmok2021-11-11 17:04:02
Python
nosmok, 2021-11-11 17:04:02

'bytes' object has no attribute 'get' how to fix error?

The problem with this part of the code is writing an error when you do a return:' return sorted([Photo(photo.get('date'),
AttributeError: 'bytes' object has no attribute 'get'
def get_photos(self, uid, qty =5):
get_url = urljoin(self.BASE_URL, 'photos.get')
resp = requests.get(get_url, params={
'access_token': self.token,
'v': self.version,
'owner_id': uid ,
'album_id': 'profile',
'photo_sizes': 1,
'extended': 1
})

return sorted([Photo(photo.get('date'),
photo.get('likes')['count'],
self.find_largest(photo.get('sizes'))) for photo in resp],
key=lambda p: p.maxsize, reverse=True)[:qty]

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
galaxy, 2021-11-11
@nosmok

If the response comes with JSON, in this case it must first be requested from the Response object:

...
self.find_largest(photo.get('sizes'))) for photo in resp.json()],

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question