I have a python script that updates a pandas dataframe to a Sharepoint List. This works fine when I run it. But after I've used PyInstaller on the python script and run it from the exe file I get: ValueError: Acquire app-only access token failed. Does anyone know why the access token failed when I run it as an exe, instead of python?
Here is the script snippet that runs successfully before Pyinstaller but unsuccessfully after pyinstaller:
site_url = ''
ctx = ClientContext(site_url).with_client_credentials(client_id, client_secret)
def add_non_empty(item_properties, key, value): #can't add empty values to sharepoint list
if pd.notna(value) and value != '':
item_properties[key] = value
### update sharepoint list 08 assessments
metadata = pd.read_excel('3_processed_output/metadata.xlsx')
list_title = '08_assessments'
list_obj = ctx.web.lists.get_by_title(list_title)
for index, row in metadata.iterrows():
item_properties = {}
add_non_empty(item_properties, 'Localtaxauthority', row.get('Local Tax Authority')
add_non_empty(item_properties, 'Assessmentnumber', row.get('Assessment Number'))
new_item = list_obj.add_item(item_properties)
ctx.execute_query()
With the exe file this result in this error:
File "B3_update_sharepoint.py", line 116, in update_sharepoint_list
File "office365\runtime\client_runtime_context.py", line 173, in execute_query
File "office365\runtime\client_request.py", line 37, in execute_query
File "office365\runtime\client_request.py", line 46, in execute_request_direct
File "office365\runtime\types\event_handler.py", line 41, in notify
File "office365\sharepoint\client_context.py", line 284, in _authenticate_request
File "office365\runtime\auth\authentication_context.py", line 249, in authenticate_request
File "office365\runtime\auth\authentication_context.py", line 206, in _authenticate
File "office365\runtime\auth\providers\acs_token_provider.py", line 34, in authenticate_request
File "office365\runtime\auth\providers\acs_token_provider.py", line 39, in ensure_app_only_access_token
File "office365\runtime\auth\providers\acs_token_provider.py", line 54, in get_app_only_access_token
ValueError: Acquire app-only access token failed.
This is the library:
I tried running the exe file similar to running the direct python code. Got access token failed after using PyInstaller. Expected to run the same as direct python compile. It has access to the same API keys in the config file.
I expected the exe to behave similar to the python script, but it blocks access after being compiled to exe file.