在 python-docx 的帮助下尝试访问存储在 aws-s3 存储桶中的 docx 类型的文件时遇到问题
Facing issues while trying to access a file of type docx stored in aws-s3 bucket with the help of python-docx
我的 aws-s3 存储桶中有一个 docx 文件。我需要使用 python-docx 阅读它。
我这样写:
from docx import Document
document = Document('https://my-first-backup-bucket-v1.s3-ap-southeast-1.amazonaws.com/New+Proposed+Quote.docx')
然后,有错误..
PackageNotFoundError:在“https://my-first-backup-bucket-v1.s3-ap-southeast-1.amazonaws.com/New+Proposed+Quote.docx”
找不到包
为什么?
当我尝试从浏览器访问同一文件时,它已成功打开。出于测试目的,我创建了具有 public 访问权限的文件,任何人都可以对此进行测试,任何人都可以对此提供帮助吗?
来自Document objects — python-docx 0.8.10 documentation:
docx.Document(docx=None)
Return a Document object loaded from docx, where docx can be either a path to a .docx file (a string) or a file-like object. If docx is missing or None, the built-in default document “template” is loaded.
意思是提供的文件名应该指向一个本地文件。它并没有说 URL 被接受。
因此,您应该从 Amazon S3 下载文件,然后在本地文件系统上指向它。
我的 aws-s3 存储桶中有一个 docx 文件。我需要使用 python-docx 阅读它。 我这样写:
from docx import Document
document = Document('https://my-first-backup-bucket-v1.s3-ap-southeast-1.amazonaws.com/New+Proposed+Quote.docx')
然后,有错误.. PackageNotFoundError:在“https://my-first-backup-bucket-v1.s3-ap-southeast-1.amazonaws.com/New+Proposed+Quote.docx”
找不到包为什么?
当我尝试从浏览器访问同一文件时,它已成功打开。出于测试目的,我创建了具有 public 访问权限的文件,任何人都可以对此进行测试,任何人都可以对此提供帮助吗?
来自Document objects — python-docx 0.8.10 documentation:
docx.Document(docx=None)
Return a Document object loaded from docx, where docx can be either a path to a .docx file (a string) or a file-like object. If docx is missing or None, the built-in default document “template” is loaded.
意思是提供的文件名应该指向一个本地文件。它并没有说 URL 被接受。
因此,您应该从 Amazon S3 下载文件,然后在本地文件系统上指向它。