Skip to content

Commit b7453a1

Browse files
committed
Fix insufficient buffer size #11
1 parent 0257a67 commit b7453a1

2 files changed

Lines changed: 11 additions & 8 deletions

File tree

lnetatmo.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ def getCameraPicture(self, image_id, key):
422422
"image_id" : image_id,
423423
"key" : key
424424
}
425-
resp = postRequest(_GETCAMERAPICTURE_REQ, postParams, json_resp=False, body_size=None)
425+
resp = postRequest(_GETCAMERAPICTURE_REQ, postParams, json_resp=False)
426426
image_type = imghdr.what('NONE.FILE',resp)
427427
return resp, image_type
428428

@@ -541,22 +541,25 @@ class WelcomeData(HomeData):
541541

542542
# Utilities routines
543543

544-
def postRequest(url, params, json_resp=True, body_size=65535):
544+
def postRequest(url, params, json_resp=True):
545545
# Netatmo response body size limited to 64k (should be under 16k)
546546
if version_info.major == 3:
547547
req = urllib.request.Request(url)
548548
req.add_header("Content-Type","application/x-www-form-urlencoded;charset=utf-8")
549549
params = urllib.parse.urlencode(params).encode('utf-8')
550-
resp = urllib.request.urlopen(req, params).read(body_size).decode("utf-8")
550+
resp = urllib.request.urlopen(req, params)
551551
else:
552552
params = urlencode(params)
553553
headers = {"Content-Type" : "application/x-www-form-urlencoded;charset=utf-8"}
554554
req = urllib2.Request(url=url, data=params, headers=headers)
555-
resp = urllib2.urlopen(req).read(body_size)
555+
resp = urllib2.urlopen(req)
556+
data = ""
557+
for buff in iter(lambda: resp.read(65535), b''):
558+
data += buff.decode("utf-8")
556559
if json_resp:
557-
return json.loads(resp)
560+
return json.loads(data)
558561
else:
559-
return resp
562+
return data
560563

561564
def toTimeString(value):
562565
return time.strftime("%Y-%m-%d_%H:%M:%S", time.localtime(int(value)))

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
setup(
66
name='lnetatmo',
7-
version='1.3.2',
7+
version='1.3.3',
88
classifiers=[
99
'Development Status :: 5 - Production/Stable',
1010
'Intended Audience :: Developers',
@@ -17,7 +17,7 @@
1717
scripts=[],
1818
data_files=[],
1919
url='https://github.com/philippelt/netatmo-api-python',
20-
download_url='https://github.com/philippelt/netatmo-api-python/tarball/1.2.2',
20+
download_url='https://github.com/philippelt/netatmo-api-python/tarball/1.3.3',
2121
license='GPL V3',
2222
description='Simple API to access Netatmo weather station data from any python script.'
2323
)

0 commit comments

Comments
 (0)