Telegram Bot - 错误请求:指定了错误的文件标识符/HTTP URL [英] Telegram Bot - Bad Request: wrong file identifier/HTTP URL specified
问题描述
我在通过 sendDocument
方法将文件上传到电报时遇到了一个奇怪的问题.我正在用 python-telegram-bot 用 python 编写一个机器人.我尝试向用户发送一个 ZIP 文件,将 URL 作为 document
.这是网址:http://telegram.someurl.tdl/32487352.zip>
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)
据我所知,我的文件遵循 Telegram 给出的规则:http://telegram.someurl.tdl/32487352.zip
As much as I know my file follows the rules given by Telegram: http://telegram.someurl.tdl/32487352.zip
- 向 Telegram 提供 HTTP URL
http://telegram.someurl.tdl/32487352.zip
2.14 MB
应用程序/zip
ZIP 文件
这些是标题:
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) 提供,配置简单.
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; } }
其中
/path/to/download_dir
当然替换为实际路径.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" }
同时发送另一个我在网上找到的 ZIP 文件:http://techslides.com/演示/样本/sample.zip
Also sending another ZIP file which I found online works: http://techslides.com/demos/samples/sample.zip
我已经搜索了解决方案,例如.这个 电报机器人奇怪的错误:错误的请求:指定了错误的文件标识符/HTTP URL 和这个 为什么我在电报机器人中收到错误的文件标识符/HTTP URL 指定错误? 没有帮助.
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.
推荐答案
我的一个朋友帮助了我,我们可以解决问题.根据 Telegram Bot API 文档,我所做的一切都是正确的,但看起来文档并不完整.
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.
问题是我的文件名.文件必须以字母开头.它不能以数字开头.所以例如.
test123.zip
和t123.zip
有效,但123.zip
或1test.zip
无效.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
andt123.zip
work but123.zip
or1test.zip
do not.2020 年 7 月更新:
似乎 Telegram 已更改其文件名政策.我只是尝试了以下名称,并且每个名称都有效.我的猜测是他们现在接受任何文件名,尽管并非每个客户端都以相同的方式保存文件:
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
测试如下:
for path in paths: print(path) chat.send_document('http://test.someurl.tdl/%s' % path, path)
这篇关于Telegram Bot - 错误请求:指定了错误的文件标识符/HTTP URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!