【问题标题】:Telegram Bot - Bad Request: wrong file identifier/HTTP URL specifiedTelegram Bot - 错误请求:指定了错误的文件标识符/HTTP URL
【发布时间】:2018-04-10 20:25:12
【问题描述】:

我在通过sendDocument 方法将文件上传到电报时遇到了一个奇怪的问题。我正在用python-telegram-bot 用python 编写一个机器人。我尝试向用户发送一个 ZIP 文件,并提供一个 URL 为document。 这是网址:http://telegram.someurl.tdl/32487352.zip

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

据我所知,我的文件遵循 Telegram 给出的规则:http://telegram.someurl.tdl/32487352.zip

  • 为 Telegram 提供 HTTP URL
    • http://telegram.someurl.tdl/32487352.zip
  • 最大 20 MB
    • 2.14 MB
  • 正确的 MIME 类型
    • application/zip
  • 通过 URL 发送目前仅适用于 gif、pdf 和 zip 文件
    • ZIP file

这些是标题:

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)

文件由 nginx (v1.10.3) 提供,配置简单。

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

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

其中/path/to/download_dir当然被替换为实际路径。

如标题所述,我得到的错误是这个:

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

还发送另一个我在网上找到的 ZIP 文件:http://techslides.com/demos/samples/sample.zip

我已经在寻找解决方案,例如。这个Telegram bot weird error : Bad Request: wrong file identifier/HTTP URL specified 和这个Why i get Wrong file identifier/HTTP URL specified error in telegram bot? 没有帮助。

希望大家能帮帮我。

【问题讨论】:

    标签: python web telegram-bot


    【解决方案1】:

    我的一个朋友帮助了我,我们可以解决这个问题。根据 Telegram Bot API 文档,我所做的一切都是正确的,但看起来文档并不完整。

    问题是我的文件名。 文件必须以字母开头。它不能以数字开头。所以例如。 test123.zipt123.zip 有效,但 123.zip1test.zip 无效。

    2020 年 7 月更新:

    Telegram 似乎改变了它的文件名政策。我只是尝试使用以下名称,并且每个名称都有效。我的猜测是他们现在接受任何文件名,尽管并非每个客户端都以相同的方式保存文件:

    \-\-\-\-.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
    

    测试如下:

    for path in paths:
        print(path)
        chat.send_document('http://test.someurl.tdl/%s' % path, path)
    

    【讨论】:

    • 我遇到了另一个问题,我正在发送带有端口的 URL。没有端口它工作。即使文件以数字开头。
    【解决方案2】:

    另外,文件名必须是英文。

    【讨论】:

    【解决方案3】:

    文件名必须至少包含 4 个字母/数字!(t12.zip 不起作用)

    【讨论】:

      猜你喜欢
      • 2018-09-13
      • 1970-01-01
      • 1970-01-01
      • 2017-07-30
      • 1970-01-01
      • 1970-01-01
      • 2021-12-29
      • 2021-07-05
      • 2018-07-25
      相关资源
      最近更新 更多