From: Marek Marecki Date: Sun, 5 May 2013 21:33:14 +0000 (+0200) Subject: Initial work on issue #14 X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=38fabb63753e20bb5cb2ad54de69cdf0e1b44094;p=diaspy.git Initial work on issue #14 --- 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