From e2fa052f5434508a6d0340e2228ef3b2ab7e9bb5 Mon Sep 17 00:00:00 2001 From: leandrotoledo Date: Wed, 9 Sep 2015 09:29:23 -0300 Subject: [PATCH] Send JSON requests over urlencoded post data --- telegram/utils/request.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/telegram/utils/request.py b/telegram/utils/request.py index 47c1d78d6..21be90d3d 100644 --- a/telegram/utils/request.py +++ b/telegram/utils/request.py @@ -84,11 +84,14 @@ def post(url, try: if InputFile.is_inputfile(data): data = InputFile(data) - request = Request(url, data=data.to_form(), headers=data.headers) - - result = urlopen(request).read() + request = Request(url, data=data.to_form(), + headers=data.headers) else: - result = urlopen(url, urlencode(data).encode()).read() + data = json.dumps(data) + request = Request(url, data=data, + headers={'Content-Type': 'application/json'}) + + result = urlopen(request).read() except HTTPError as error: message = _parse(error.read()) raise TelegramError(message)