首页 > 解决方案 > 如何在 python 中使用 twilio api 将本地文件作为传真发送?

问题描述

我是 twilio 和 python 的新手。我想使用 twilio api 构建一个简单的传真命令。所以我使用它,它工作得很好

 fax = client.fax.faxes \
.create(
     from_="+18566198960",
     media_url="https://www.twilio.com/docs/documents/25/justthefaxmaam.pdf",
     to="+14105210871"
 )

print(fax.sid)

但是,我想将 media_url 更改为位于 doc 文件夹中的本地文件,所以我使用这个 media_url

 media_url="../doc/testfax.doc"

但我得到这个错误

HTTP 错误您的请求是:

邮寄/传真

Twilio 返回以下信息:

无法创建记录:参数“MediaUrl”无效

更多信息可在此处获得:

https://www.twilio.com/docs/errors/20001

如何分配本地文件作为要发送的传真内容?

标签: pythontwiliofax

解决方案


我查看了用于发送传真的 Twilio API - https://www.twilio.com/docs/fax/send

这个需要:

* A destination phone number or SIP URI.
* A From number - this can be either an Incoming Phone Number or an Outgoing  Caller ID. (Optional for SIP destinations.)
* A URL which points to the media that will be sent via fax (currently, this must be a PDF file; see our security page for information on how to ensure the request for your media comes from Twilio).

API 不支持本地文件(只有 URL,带有 PDF 文件)。


推荐阅读