mirror of
https://github.com/python-telegram-bot/python-telegram-bot.git
synced 2025-01-08 19:34:12 +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:
|
||||
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)
|
||||
|
|
Loading…
Reference in a new issue