Nachtalb
Nachtalb

Reputation: 355

Telegram Bot - Bad Request: wrong file identifier/HTTP URL specified

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

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.

Upvotes: 1

Views: 11769

Answers (3)

Nachtalb
Nachtalb

Reputation: 355

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)

Upvotes: 7

rkcell
rkcell

Reputation: 468

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

Upvotes: 1

user5713140
user5713140

Reputation:

Also, the file-name must be in English.

Upvotes: 0

Related Questions