Skip to content

Commit

Permalink
Fix insufficient buffer size #11
Browse files Browse the repository at this point in the history
  • Loading branch information
philippelt committed Jun 12, 2017
1 parent 0257a67 commit b7453a1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
15 changes: 9 additions & 6 deletions lnetatmo.py
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ def getCameraPicture(self, image_id, key):
"image_id" : image_id,
"key" : key
}
resp = postRequest(_GETCAMERAPICTURE_REQ, postParams, json_resp=False, body_size=None)
resp = postRequest(_GETCAMERAPICTURE_REQ, postParams, json_resp=False)
image_type = imghdr.what('NONE.FILE',resp)
return resp, image_type

Expand Down Expand Up @@ -541,22 +541,25 @@ class WelcomeData(HomeData):

# Utilities routines

def postRequest(url, params, json_resp=True, body_size=65535):
def postRequest(url, params, json_resp=True):
# Netatmo response body size limited to 64k (should be under 16k)
if version_info.major == 3:
req = urllib.request.Request(url)
req.add_header("Content-Type","application/x-www-form-urlencoded;charset=utf-8")
params = urllib.parse.urlencode(params).encode('utf-8')
resp = urllib.request.urlopen(req, params).read(body_size).decode("utf-8")
resp = urllib.request.urlopen(req, params)
else:
params = urlencode(params)
headers = {"Content-Type" : "application/x-www-form-urlencoded;charset=utf-8"}
req = urllib2.Request(url=url, data=params, headers=headers)
resp = urllib2.urlopen(req).read(body_size)
resp = urllib2.urlopen(req)
data = ""
for buff in iter(lambda: resp.read(65535), b''):
data += buff.decode("utf-8")
if json_resp:
return json.loads(resp)
return json.loads(data)
else:
return resp
return data

def toTimeString(value):
return time.strftime("%Y-%m-%d_%H:%M:%S", time.localtime(int(value)))
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

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

0 comments on commit b7453a1

Please sign in to comment.