做电子委托在那个网站seo权重优化
因为我参考minio的文档操作,当时文档并不是很详细,这篇博文会统一记录自己所遇到的问题。以下的每个标题都是具体的错误信息。
minio-py文档
错误1:SSL: WRONG_VERSION_NUMBER
这个错误的原因是在创建minio的客户端时候没有关闭SSL,请使用如下的代码:
minio_client = Minio(endpoint=file_settings.ENDPOINT,access_key=file_settings.ACCESS_KEY,secret_key=file_settings.SECRET_KEY,secure=False, # 加上即可解决错误)
错误2:path in endpoint is not allowed
因为在官网使用的是minio的playground,而不是本地的这样连接方法,因此如果你的endpoint是http://127.0.0.1:9000
,就会报错,正确的endpoint地址应该是127.0.0.1:9000
错误3:S3 giving me NoSuchKey error even when the key exists
这个错误有点误导性,观察Key会以为是自己的access_key,secret_key
的问题,但是并不是,实际上,文件的名称被称为Object Key
,即对象箭,所以请再次检查你的文件名是否正确,比如我的文件名因为涉及文件夹,所以会很复杂,可以尝试打印出具体source object,检查地址是否和web页面上的地址一致。
错误4:‘utf-8’ codec can’t decode byte 0xa1 in position 10: invalid start byte
我的minio中的文件是一个pdf,我想要获取其中的文字,原始的代码,即从response中读取数据,如下:
# Get document from minio server
response = minio_client.get_object(bucket_name="file",object_name="1768107746265141248/3hpLARbrpT1dYEp83zscg2l4X1VYCYkXxKQHs1c7bjQ=/1768176834878382080")
# Read data directly from the response
data = response.data.decode()
注意默认的解析方式是utf-8,也可以尝试其它的编码方式
,但是无论尝试其它任何的编码,似乎都无法成功。需要注意的是,获取的是文件,因此应该将其转换为io流,然后读取其中的文字
代码应当如下:
response = minio_client.get_object(bucket_name="file",object_name="1768107746265141248/3hpLARbrpT1dYEp83zscg2l4X1VYCYkXxKQHs1c7bjQ=/1768176834878382080")
# Write response data to memory stream
data_stream = io.BytesIO(response.read())
pdf_file = fitz.open(stream=data_stream, filetype="pdf")
# Traverse each page
page_text = ""
for page_index in range(len(pdf_file)):page = pdf_file[page_index]page_text = page_text + page.get_text()
print(page_text)