나는 사용자의 로컬 디렉토리에서 대상 경로를 생성하는 사용자의 보관 account.While에서 파일을 다운로드하는 보관 용 응용 프로그램을 구현하기 위해 노력하고 허용되지 않습니다, 그것은잘못된 경로가 백 슬래시는
오류가 발생 말하는 충돌하는 [400] {U를 '경로 : u''invalid 경로/새 폴더 \\ img1.jpg : 인덱스 11 백 슬래시의 문자는 내가 보관의 폴더 계층 앞으로 사용 dorectories의 중첩을 나타 내기 위해 슬래시 생각
} 허용되지, 창문 뒤로 사용 슬래시 때문에 충돌 할 수 있습니다. 그럼 난 다른 경로에 대한
sample_path.replace 다음과 같이 파이썬의 BIF는 ("\\"를 "/")) (
하지만 여전히
을 대체 사용complete_path
내 코드에서 변수가 백 슬래시가 포함 된 경로를 제공하면 프로그램이 충돌합니다. 내 보관 용 계정의 폴더 계층 구조는 다음과 같습니다
New Folder :
Img1.jpg
dtu.jpg
img.jpg
코드는 다음과 같습니다
>>> x = "hello"
>>> x.replace("hello", "goodbye")
'goodbye'
>>> x
'hello'
가에 replace
를 호출 :
def download_file(self,source_path,target_path):
print 'Downloading %s' % source_path
file_path = os.path.expanduser(target_path)
(dir_path,tail) = os.path.split(target_path)
self.check_dir(dir_path)
to_file = open(file_path,"wb")
print source_path+"!!!!!!!!!!!!!!!!!!!!!!!!!!"
source_path.replace("\\","/")
f= self.mClient.get_file(source_path) # request to server !
to_file.write(f.read())
return
def download_folder(self, folderPath):
# try to download 5 times to handle http 5xx errors from dropbox
try:
response = self.mClient.metadata(folderPath)
# also ensure that response includes content
if 'contents' in response:
for f in response['contents']:
name = os.path.basename(f['path'])
complete_path = os.path.join(folderPath, name)
if f['is_dir']:
# do recursion to also download this folder
self.download_folder(complete_path)
else:
# download the file
self.download_file(complete_path, os.path.join(self._target_folder, complete_path))
else:
raise ValueError
except (rest.ErrorResponse, rest.RESTSocketError, ValueError) as error:
print 'An error occured while listing a directory. Will try again in some seconds.'
print "Error occured "+ str(error)
어떻게 이러한 함수를 호출합니까? 너는 창문에서 뛰고있어? –
함수 호출은 main() -> init_download() -> download_folder()처럼 링크를 호출합니다. – vertexion
btw를 대체하고 퍼팅하는 것은 도움이되지 않습니다. 경로 모듈을 사용하면 아무 것도 교체하지 않고도 작동합니다. 서버로 보내기 전에 경로 만 바꿉니다. –