Office365-REST-Python-Client icon indicating copy to clipboard operation
Office365-REST-Python-Client copied to clipboard

addItem method can't find serverRelativeUrl variable and crashes

Open skaradub opened this issue 2 years ago • 1 comments

hello there! Working a bit with sharepoint lists (reading) - everything is OK. but cant add item, Lib cant find serverRelativeURL

def get_ctx(msalapp):
    base_url = BASE_URL
    auth_context = AuthenticationContext(base_url)
    auth_context.register_provider(acquire_token_gen(msalapp, base_url))
    return ClientContext(base_url=base_url, auth_context=auth_context)

ctx = get_ctx(msalapp)

list_itself = find_list('tags',ctx)   ## ctx.web.lists.get_by_title(list_title)
my_data = data=[{'dashboard_id': 'test1','name':'test1'},{'owner': 'testov','business_unit':'market'}]

new_item = list_itself.add_item(my_data)
ctx.execute_query()

get error

~/.local/lib/python3.7/site-packages/office365/sharepoint/lists/list.py in _resolve_folder_url()
    248         else:
    249             def _resolve_folder_url():
--> 250                 list_item_creation_information.FolderUrl = self.context.base_url + self.root_folder.serverRelativeUrl
    251                 add_item_qry = ServiceOperationQuery(
    252                     self,

TypeError: can only concatenate str (not "NoneType") to str

skaradub avatar Jan 13 '23 12:01 skaradub

I've seen the same thing - I think it's because serverRelativeUrl is a property that returns self.properties.get("ServerRelativeUrl", None). Weirdly enough I've resolved it in some scenarios by implementing a check like this before I have to use that property

while sharepoint_dir.serverRelativeUrl is None:
    sleep(1)

For some reason waiting a second can result in the value being defined for the Folder

JWBWork avatar May 03 '23 19:05 JWBWork