Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
86 views
in Technique[技术] by (71.8m points)

python - Error code -2130575338 library office365.runtime.auth.authentication_context

from office365.runtime.auth.authentication_context import AuthenticationContext
from office365.runtime.http.request_options import RequestOptions
from office365.sharepoint.client_context import ClientContext
from office365.sharepoint.files.file    import File
ctx_auth = AuthenticationContext("https://infarmahonduras.sharepoint.com/sites/ContabilidadInfarma")   
ctx_auth.acquire_token_for_user("xxxxxxxx","xxxxxxx")   
ctx = ClientContext("https://infarmahonduras.sharepoint.com/sites/ContabilidadInfarma", ctx_auth)
relative_url= "/sites/ContabilidadInfarma/Documents/Mercadeo202005.xlsx"
filename = 'Mercadeo202005.xlsx'
with open(filename, 'wb') as output_file:
    response = File.open_binary(ctx, relative_url)
    output_file.write(response.content)
print(response.content)**

#I have the problem that it downloads the file but it is not more than 1 kb and the original file size is 189 kb when changing the extension to XLS the following error is written

{"error":{"code":"-2130575338, Microsoft.SharePoint.SPException","message":{"lang":"es-ES","value":"El archivo /sites/ContabilidadInfarma/Documents/Mercadeo202005.xlsx no existe."}}}'

question from:https://stackoverflow.com/questions/65887834/error-code-2130575338-library-office365-runtime-auth-authentication-context

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

@FernandoGFMC,

I tested your code on my SPO environment, here it works well. From the error msg, it seems that the relative_url of the file is not correct.

If your file is in the default library, the ServerRelativeUrl should be:

/sites/{site}/Shared Documents/{filename}.xlsx

'Documents' is the list name while Shared Documents is the root folder. In fact, I am able to produce the error if I set a wrong URL:

enter image description here

BR


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...