1

I have a weird problem with uploading a file to telegram via the sendDocument method. I am writing a bot in python with python-telegram-bot. I try to send a ZIP file to a user, giving a URL as document. This is the URL: http://telegram.someurl.tdl/32487352.zip

bot.send_document(
    chat_id,
    document=document,
    filename=filename,
    timeout=60)

As much as I know my file follows the rules given by Telegram: http://telegram.someurl.tdl/32487352.zip

  • Provide Telegram with an HTTP URL
    • http://telegram.someurl.tdl/32487352.zip
  • 20 MB max
    • 2.14 MB
  • correct MIME type
    • application/zip
  • sending by URL will currently only work for gif, pdf and zip files
    • ZIP file

These are the headers:

Accept-Ranges →bytes
Connection →keep-alive
Content-Length →2247049
Content-Type →application/zip
Date →Sun, 29 Oct 2017 21:15:36 GMT
ETag →"59f5e6e6-224989"
Last-Modified →Sun, 29 Oct 2017 14:34:14 GMT
Server →nginx/1.10.3 (Ubuntu)

The file is served by nginx (v1.10.3), with this simple configuration.

server {
    listen 80;
    server_name telegram.someurl.tdl;

    root /path/to/download_dir;
    location / {
        try_files $uri $uri/ =404;
    }
}

Where /path/to/download_dir is replaced with the actual path of course.

The error I get, as said in the title, is this one:

{
    "ok": false,
    "error_code": 400,
    "description": "Bad Request: wrong file identifier/HTTP URL specified"
}

Also sending another ZIP file which I found online works: http://techslides.com/demos/samples/sample.zip

I already searched for a solution and eg. this Telegram bot weird error : Bad Request: wrong file identifier/HTTP URL specified and this Why i get Wrong file identifier/HTTP URL specified error in telegram bot? do not help.

I hope you guys can help me with this.

3 Answers 3

7

A friend of mine helped me and we could fix the problem. Everything I did was correct according to the Telegram Bot API documentation, but as it looks the documentation is not complete.

The problem was the name of my file. The file must start with a letter. It cannot start with a number. So eg. test123.zip and t123.zip work but 123.zip or 1test.zip do not.

Update July 2020:

It seems that Telegram has changed it's filename policy. I just tried with the following names and every single one worked. My guess is they accept any filename now though not every client saves the file the same way:

\-\-\-\-.zip   # in Telegram Desktop on Windows shown as "\-\-\-\-.zip" but saved as "_-_-_-_-.zip"
               # in Telegram on Android shown and saved as "----.zip"
hällo.zip
1.zip
test\nme.zip   # even with a filename with a literal new line character
               # in Telegram Desktop on Windows shown as "testme.zip" but saved as "test_me.zip"
               # in Telegram on Android shown and saved as "testme.zip"
tttt.zip
!test.zip
test!.zip
ttt.zip
t.zip
t1.zip
1t.zip
000.zip
äääää.zip

tested as follows:

for path in paths:
    print(path)
    chat.send_document('http://test.someurl.tdl/%s' % path, path)
Sign up to request clarification or add additional context in comments.

1 Comment

I've had another problem, I was sending URL with port. Without port it worked. Even when file starts with a digit.
1

The filename must be at least 4 letters/digits long! (t12.zip wouldn't work)

Comments

0

Also, the file-name must be in English.

2 Comments

This does not provide an answer to the question. Once you have sufficient reputation you will be able to comment on any post; instead, provide answers that don't require clarification from the asker. - From Review
I just added valuable missed info to the previous answer. Note, the author and me reveal undocumented tricks.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.