Telegram Bot - 错误请求:指定了错误的文件 identifier/HTTP URL
Telegram Bot - Bad Request: wrong file identifier/HTTP URL specified
我在通过 sendDocument
方法将文件上传到电报时遇到了一个奇怪的问题。我正在用 python-telegram-bot 在 python 中编写一个机器人。我尝试向用户发送一个 ZIP 文件,将 URL 作为 document
。
这是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
- 为 Telegram 提供 HTTP URL
http://telegram.someurl.tdl/32487352.zip
- 最大 20 MB
2.14 MB
- 正确的 MIME 类型
application/zip
- 通过 URL 发送目前仅适用于 gif、pdf 和 zip 文件
ZIP file
这些是 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)
该文件由 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
我已经在寻找解决方案,例如。这 and this 没有帮助。
希望大家能帮帮我。
我的一个朋友帮助了我,我们可以解决这个问题。根据 Telegram Bot API 文档,我所做的一切都是正确的,但看起来文档并不完整。
问题出在我的文件名上。 文件必须以字母开头。它不能以数字开头。所以例如。 test123.zip
和 t123.zip
有效,但 123.zip
或 1test.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)
此外,文件名必须是英文。
文件名必须 至少 4 letters/digits 长!(t12.zip 无效)
我在通过 sendDocument
方法将文件上传到电报时遇到了一个奇怪的问题。我正在用 python-telegram-bot 在 python 中编写一个机器人。我尝试向用户发送一个 ZIP 文件,将 URL 作为 document
。
这是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
- 为 Telegram 提供 HTTP URL
http://telegram.someurl.tdl/32487352.zip
- 最大 20 MB
2.14 MB
- 正确的 MIME 类型
application/zip
- 通过 URL 发送目前仅适用于 gif、pdf 和 zip 文件
ZIP file
这些是 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)
该文件由 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
我已经在寻找解决方案,例如。这 and this 没有帮助。
希望大家能帮帮我。
我的一个朋友帮助了我,我们可以解决这个问题。根据 Telegram Bot API 文档,我所做的一切都是正确的,但看起来文档并不完整。
问题出在我的文件名上。 文件必须以字母开头。它不能以数字开头。所以例如。 test123.zip
和 t123.zip
有效,但 123.zip
或 1test.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)
此外,文件名必须是英文。
文件名必须 至少 4 letters/digits 长!(t12.zip 无效)