mirror of
https://github.com/python-telegram-bot/python-telegram-bot.git
synced 2025-01-09 11:44:22 +01:00
Send JSON requests over urlencoded post data
This commit is contained in:
parent
dcfe08dbda
commit
e2fa052f54
1 changed files with 7 additions and 4 deletions
|
@ -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)
|
||||||
|
|
Loading…
Reference in a new issue