@vgrem ๋ , ๋ค์ ์ฝ๋๋ ValueError
์ํต๋๋ค.
...
web = client_context.web
client_context.load(web)
server_relative_url = f'/{folder_name}/{filename}'
logger.info(f'relative path: {server_relative_url}')
file = web.get_file_by_server_relative_url(server_relative_url)
return file.read()
๋ค์๊ณผ ๊ฐ์ด ํด๋น ์ค๋ฅ์ ์ผ๋ถ ๋ฉ์์ง๋ฅผ ์ถ๊ฐํ๋ ๊ฒ์ด ์ข์ต๋๋ค.
```
raise ValueError('๋น์ ์ ์ด๊ฒ๊ณผ ์ ๊ฒ์ ์๋ชปํ์ต๋๋ค...')
file.read()
์ ์ ์ด๊ฒ์ ์ถ๊ฐํ๋ฉด ๋ด ๋ฌธ์ ๊ฐ ํด๊ฒฐ๋ฉ๋๋ค.
client_context.load(file)
client_context.execute_query()
๋ง์ต๋๋ค. File.read
๋ฉ์๋๋ ํ์ผ์ด ๋ค์ด๋ก๋๋๊ธฐ ์ ์ ํ์ผ ๋ฉํ๋ฐ์ดํฐ(ํนํ ํ์ผ ์ฃผ์๋ฅผ ์ฌ๋ฐ๋ฅด๊ฒ ์ง์ ํ๊ธฐ ์ํด ServerRelativeUrl
์์ฑ)๊ฐ ๊ฒ์๋ ๊ฒ์ผ๋ก ์์ํฉ๋๋ค.
client_context.load(file)
client_context.execute_query()
ํ์ผ ์ฝํ
์ธ ๋ฅผ ๋ค์ด๋ก๋ํ๋ ๊ฒ์ด ๊ฐ์ฅ ์ง๊ด์ ์ด์ง ์์ ์ ์์ผ๋ฏ๋ก File.download
๋ค๋ฅธ ๋ฐฉ๋ฒ์ด ๋์
๋์์ผ๋ฉฐ ์ด์ ๋ค์๊ณผ ๊ฐ์ด ํ์ผ์ ๋ค์ด๋ก๋ํ ์ ์์ต๋๋ค.
with open(download_path, "wb") as local_file:
source_file = ctx.web.get_file_by_server_relative_url(file_url)
source_file.download(local_file)
ctx.execute_query()
@vgrem ์๊ฒ ๊ฐ์ฌ
file.download๋ 2.1.7.post1์ ์ผ๋ถ์ ๋๊น?
pip์ ์ต์ ๋ฒ์ ์ ๊ทธ ์ ๋๊น์ง๋ง ๊ฐ ์ ์์ต๋๋ค.
ํ ๋ชฉ๋ก | grep -i ์ฌ๋ฌด์ค
Office365-REST-ํ์ด์ฌ-ํด๋ผ์ด์ธํธ 2.1.7.post1
2.1.8
pip ์ค์น --์
๊ทธ๋ ์ด๋ Office365-REST-Python-Client==2.1.8
์ค๋ฅ: Office365-REST-Python-Client==2.1.8 ์๊ตฌ ์ฌํญ์ ์ถฉ์กฑํ๋ ๋ฒ์ ์ ์ฐพ์ ์ ์์ต๋๋ค(๋ฒ์ : 1.0.0, 1.0.1, 1.1.0, 2.0.0, 2.1.1, 2.1.2). , 2.1.3, 2.1.4, 2.1.5, 2.1.6.post2, 2.1.7.post1)
์ค๋ฅ: Office365-REST-Python-Client==2.1.8์ ๋ํด ์ผ์นํ๋ ๋ฐฐํฌํ์ ์ฐพ์ ์ ์์ต๋๋ค.
==== ์์ ํด๊ฒฐ ๋ฐฉ๋ฒ ====
์์ ํ์ผ ๊ฐ์ ธ์ค๊ธฐ
์์
OS
๋ค์ด๋ก๋ ๊ฒฝ๋ก = os.path.join(tempfile.mkdtemp(), os.path.basename(์์น))
file_url = '/์ฌ์ดํธ/ํตํฉ/๊ณต์ ๋ฌธ์/SomeFolder/somefile.csv'
๋ค์ด๋ก๋ ๊ฒฝ๋ก = os.path.join(tempfile.mkdtemp(), os.path.basename(file_url))
๋ค์ด๋ก๋ ๊ฒฝ๋ก
open(download_path, "wb")์ local_file๋ก ์ฌ์ฉ:
์์ค ํ์ผ = ctx.web.get_file_by_server_relative_url(file_url)
์์ค ํ์ผ
ctx.load(์์ค ํ์ผ)
ctx.execute_query()
r = source_file.read()
ctx.execute_query()
print("๋ฐ์ดํฐ:", r)
local_file.write(r)
local_file.close()
print("[ํ์ธ] ํ์ผ์ด ๋ค์ด๋ก๋๋์์ต๋๋ค: {0}".format(download_path))