python3 FastDFS客户端连接
2019-09-25 本文已影响0人
还是那个没头脑
安装
pip install py3Fdfs
py3fdfs源于fdfs-client,但在使用过程中, 和旧版略有不同.(py3fdfs官网示例有误)
创建client实例对象的时候不能直接传入配置文件的地址字符串,否则报错.
错误代码:TypeError: type object argument after ** must be a mapping, not str
通过模块内get_tracker_conf函数, 获取配置文件后传入
from fdfs_client.client import Fdfs_client,get_tracker_conf
try:
tracker_path = get_tracker_conf('E:/×××/client.conf') #绝对路径
client = Fdfs_client(tracker_path)
# ret_upload
ret_upload= client.upload_by_filename('E:/×××/img/0146000027.jpg')
print(ret_upload)
# download
ret_download = client.download_to_file(local_filename, file_id)
print(ret_download)
# delete 注:file_id为bytes类型
file_id = ret_upload['Remote file_id']
ret_delete = client.delete_file(file_id )
print(ret_delete)
except Exception as e:
print('连接失败', e)
client.conf配置文件
connect_timeout=30
network_timeout=60
# 日志存放路径
base_path=E:\h_resource\GUI
# tracker服务器的ip
tracker_server = IP:22122
# tracker服务器的端口
http.tracker_server_port = 80