http icon indicating copy to clipboard operation
http copied to clipboard

MultipartRequest weird behavior using Telegram API

Open muniz95 opened this issue 8 years ago • 10 comments

Hi. I am developing a bot wrapper for Telegram, and I am using MultipartRequest class to send a file from my local machine to the Telegram servers, but I am facing a 504 error all the time. No matter the parameters I'm using, I get this error after a long waiting time.

Even without any file attached this actions results in an error. Here is a snippet of the code I'm using. A simple curl with exactly the same parameters is successful.

As far as I tested, this only occours with Telegram.

muniz95 avatar Mar 17 '17 20:03 muniz95

Are you using http 0.11.3+12? That includes a multipart bug fix that might fix your issue.

nex3 avatar May 15 '17 19:05 nex3

I just tested it with version 0.11.3+13, and the Gateway Timeout is still happening.

muniz95 avatar May 16 '17 12:05 muniz95

In that case, I need more information to determine what's different between the requests we're sending and those curl is sending. If you can provide a standalone example—one that doesn't require telegram's servers—that chokes on our multipart requests, that would be great. Otherwise, you may have to do some trial-and-error with manual HTTP requests to figure out exactly what it is about our requests that's causing Telegram to choke.

nex3 avatar May 17 '17 04:05 nex3

https://github.com/dart-lang/http/issues/62

graddotdev avatar May 29 '17 15:05 graddotdev

Sorry for the VERY late response. I am using the newest version of http (0.11.3+16) Here is a snippet of my code:

main() {
  // I created a new bot in order to test it, so this token actually works
  String uri = 'https://api.telegram.org/bot511.../sendPhoto';
  var request = new MultipartRequest("POST", uri);
  // var file = new File('${dirname(Platform.script.path)}/photo.jpg').readAsBytesSync();
  var requestFile = await MultipartFile.fromPath('photo', '${dirname(Platform.script.path)}/photo.jpg');
  request.fields['chat_id'] = '299327540';
  request.files.add(requestFile);
  request
    .send()
    .then((response) => print(response.reasonPhrase));
}

The file photo.jpg is placed in the same folder of the script. I am still unable to send any file using this method

muniz95 avatar Dec 27 '17 14:12 muniz95

I still need more information about the difference between what's happening at a protocol level here between http and curl.

nex3 avatar Jan 02 '18 23:01 nex3

The curl command I used for tests is the following:

/usr/bin/curl -F "chat_id=012345" -F "audio=@'/path/to/audio.mp3'" 'https://api.telegram.org/bot511055718:AAFM5QO7w-Yt1v6-wjIdaqI2ylA50voSln4/sendAudio'

I am not using any extra header, except the multipart/form-data where necessary. The requests are basically the same.

muniz95 avatar Jan 03 '18 01:01 muniz95

I need to see the actual bytes that are being sent to the server in each case—I don't want to try to reproduce this locally and risk messing with your bot or whatever.

nex3 avatar Jan 03 '18 01:01 nex3

This is a bot intended to be a testing bot, you can use it freely.

I don't know how to get all bytes from the file anyway.

Em ter, 2 de jan de 2018 23:43, Natalie Weizenbaum [email protected] escreveu:

I need to see the actual bytes that are being sent to the server in each case—I don't want to try to reproduce this locally and risk messing with your bot or whatever.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/dart-lang/http/issues/69#issuecomment-354921270, or mute the thread https://github.com/notifications/unsubscribe-auth/AEdF6vKU2XiZkwP6xoVEVomAg2fIuAHWks5tGtsogaJpZM4MhEvp .

-- [image: Visualizar meu perfil no LinkedIn] Visualizar perfil de Rodrigo Muniz https://br.linkedin.com/pub/rodrigo-muniz/33/400/236

muniz95 avatar Jan 03 '18 11:01 muniz95

I'm trying to reproduce this with a curl call, but I keep getting 400 errors with the description "Bad Request: chat not found".

nex3 avatar Jan 03 '18 22:01 nex3

Without additional information we're not able to resolve this issue. Feel free to add more info or respond to any questions above and we can reopen the case. Thanks for your contribution!

github-actions[bot] avatar Nov 01 '24 08:11 github-actions[bot]