【发布时间】:2019-10-07 09:28:13
【问题描述】:
我正在尝试使用 stripe.File.create() 方法将文件从 firebase 数据库传输到 Stripe。这是我正在使用的代码:
file_url = storage.child("/path/to/file").get_url(token=None)
response = requests.get(file_url, stream=True)
img = Image.open(BytesIO(response.content))
stripe.File.create(
purpose="identity_document",
file=img
)
但是当我运行这段代码时,我得到:
Request req_E7fskNVgpHHlRm: Invalid hash
我相信我从 firebase 获得了正确的图像,因为我可以运行以下行并将图像保存到我的本地驱动器:
img.save("test.jpg")
但 Stripe 似乎不喜欢我提供的文件格式。我相信该文件必须以二进制模式提供,所以也许我只需要编辑img = Image.open(BytesIO(response.content)) 行即可以二进制模式获取文件。
感谢任何反馈。
【问题讨论】:
-
您在发送文件时是否设置了正确的 MIME 类型?看看stripe.com/docs/file-upload#uploading-a-file
-
如何指定 MIME 类型?是在文件头吗?我可以另存为.jpg。该文档没有显示如何设置正确的 MIME 类型
标签: python python-requests stripe-payments python-imageio