Open Ajinkz opened 3 years ago
I was able to execute the following lines of code on a local machine but failed to run AWS lambda
from shareplum import Site
from shareplum import Office365
from shareplum.site import Version
import shareplum
print(shareplum.__version__)
username = config['sp_user'] # user mail id
password = config['sp_password']
basepath = config['sp_base_path'] # 'https://xxxxxxx.sharepoint.com/'
sitename = config['sp_site_name'] # 'https://xxxxxxx.sharepoint.com/sites/xxxxxx'
dirname = 'testdir' # directory where file is suppose to upload
authcookie = Office365(basepath, username=username, password=password).GetCookies()
site = Site(sitename,version=Version.v365, authcookie=authcookie)
spfolder = site.Folder('Shared Documents/'+ dirname)
allfiles = spfolder.files
for file in allfiles:
print(file['Name'])
filename = '/tmp/'+ 'test-'+str(dateobj.date())+".csv"
#
with open(filename,'rb') as file_input:
print("Filename:",filename)
try:
#fileContent = file_input.read()
spfolder.upload_file(file_input, filename)
print("file uploaded")
except Exception as err:
print("\nERROR occurred: \n" + str(err))
Error
Shareplum HTTP Post Failed : 400 Client Error: Bad Request for url: https://xxxxxxxx.sharepoint.com/sites/sharedlib/_api/web/GetFolderByServerRelativeUrl('Shared%20Documents/testdir')/Files/add(url='/tmp/test-2021-11-10.csv',overwrite=true)
I'm able to get the list of files from the SharePoint location but I'm unable to upload the file using AWS Lambda. Same code tested locally which runs fine but failed to work on Lambda
I'm using the following version of Layer in Lambda. shareplum-9263cd6b-1270-42a8-9b2f-a647a9f25a47.zip
I am currently fighting problems with using this code on Azure Functions. I found some problems with including the correct dependencies. It is important to double-check, as the requirements for the most current version can be found below.
Just an idea.
Regards
certifi==2019.11.28 cffi==1.14.0 chardet==3.0.4 cryptography==3.3.2 idna==2.9 lxml==4.6.5 ntlm-auth==1.4.0 pycparser==2.20 requests==2.23.0 requests-ntlm==1.1.0 requests-toolbelt==0.9.1 SharePlum==0.4.2 six==1.14.0 urllib3==1.26.5
I don't have any experience with that. I would assume that there are no issues as long as you can log into you SharePoint account from the Lambda server.