Send JSON requests over urlencoded post data

This commit is contained in:
leandrotoledo 2015-09-09 09:29:23 -03:00
parent dcfe08dbda
commit e2fa052f54

View file

@ -84,11 +84,14 @@ def post(url,
try: try:
if InputFile.is_inputfile(data): if InputFile.is_inputfile(data):
data = InputFile(data) data = InputFile(data)
request = Request(url, data=data.to_form(), headers=data.headers) request = Request(url, data=data.to_form(),
headers=data.headers)
result = urlopen(request).read()
else: 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: except HTTPError as error:
message = _parse(error.read()) message = _parse(error.read())
raise TelegramError(message) raise TelegramError(message)