From 38fabb63753e20bb5cb2ad54de69cdf0e1b44094 Mon Sep 17 00:00:00 2001 From: Marek Marecki Date: Sun, 5 May 2013 23:33:14 +0200 Subject: [PATCH] Initial work on issue #14 --- diaspy/streams.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/diaspy/streams.py b/diaspy/streams.py index a91a376..d0246a7 100644 --- a/diaspy/streams.py +++ b/diaspy/streams.py @@ -169,21 +169,25 @@ class Stream(Generic): :param filename: Path to picture file. :type filename: str """ - aspects = self._connection.getUserInfo()['aspects'] + data = open(filename, 'rb') + image = data.read() + data.close() + params = {} params['photo[pending]'] = 'true' params['set_profile_image'] = '' params['qqfile'] = filename + aspects = self._connection.getUserInfo()['aspects'] for i, aspect in enumerate(aspects): - params['photo[aspect_ids][%d]' % (i)] = aspect['id'] - - data = open(filename, 'rb') + params['photo[aspect_ids][{0}]'.format(i)] = aspect['id'] headers = {'content-type': 'application/octet-stream', 'x-csrf-token': self._connection.get_token(), 'x-file-name': filename} - request = self._connection.post('photos', params=params, data=data, headers=headers) - data.close() + + request = self._connection.post('photos', data=image, params=params, headers=headers) + if request.status_code != 200: + raise Exception('wrong error code: {0}'.format()) return request -- 2.25.1