刚刚在使用fdfs分布式存储的python客户端上传从文件时,出现下面这个问题
使用环境为:python版本:python 2.6.6
fdfs 版本:5.05
服务器操作系统:centos
fdfs_client_py版本:1.2.6
fdfs_client_py版本的github地址为:https://github.com/hay86/fdfs_client-py
上传文件时出现如下问题:
raise DataError('[-] Error:%d,s'%(th.status,os.strerror(th.status)))
DataEoor:[-] Error:2,No such file or directory
根据提示,可以知道是从文件上传失败,说没有这个文件或目录,但是明明我的本地有这个从文件。
我将 python版本换成2.7.3也没用
将fdfs_client_py换成最新版也还是没用
但是我直接使用它的源码下的测试程序却上传主文件和从文件都没问题,如下所示:
难道是我的上传代码写的有问题,我是这样写的:
def upload_file(self,filePath=None,slaveFilePath=None):
#upload the apk and the apk details html file into fastdfs storage
#apk file as master file while html file as slave file
if filePath is None:
return None
ret={}
client=Fdfs_client(self.m_clientConf)
result=client.upload_by_filename(filePath) #upload master file
master_fileId=''
if result is not None: #success
self.m_logger.info(" save %s into fdfs success"%filePath)
print " save %s into fdfs success"%filePath
print result
ret['storageIp']=result['Storage IP']
ret['groupName']=result['Group name']
ret['masterFileId']=result['Remote file_id']
master_fileId=result['Remote file_id']
print slaveFilePath,master_fileId
if(slaveFilePath is not None): #upload slave file
slave_res=client.upload_slave_by_filename(slaveFilePath,master_fileId,'-html')
if slave_res is not None: #success
self.m_logger.info(" save slave %s into fdfs success"%slaveFilePath)
ret['slaveFileId']=slave_res['Remote file_id']
return ret #return the storage info
但是当我改为如下,即直接指定主文件id ,又可以上传从文件了,当然这个主文件id必须存在
def upload_file(filePath=None,slaveFilePath=None):
#upload the apk and the apk details html file into fastdfs storage
#apk file as master file while html file as slave file
if filePath is None:
return None
ret={}
client=Fdfs_client('client.conf')
'''
result=client.upload_by_filename(filePath) #upload master file
master_fileId=''
if result is not None: #success
ret['storageIp']=result['Storage IP']
ret['groupName']=result['Group name']
ret['masterFileId']=result['Remote file_id']
master_fileId=result['Remote file_id']
print 'ret',ret
'''
if(slaveFilePath is not None): #upload slave file
file_prefix='-html'
slave_res=client.upload_slave_by_filename(slaveFilePath,"group1/M00/00/00/wKgLNFZMJQqAMZd1AAAFDeT7vec1033.py",file_prefix)
if slave_res is not None: #success
ret['slaveFileId']=slave_res['Remote file_id']
return ret #return the storage info
这是什么情况,难道我上传主文件时返回的主文件id是错的吗?
于是我把服务器上的python重装成2.7,3的,结果再导入这个fdfs_client的包时提示:
ImportError: No module named sendfile
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
上面的问题还没有解决,等解决了再更新