mirror of
https://github.com/open-webui/oikb.git
synced 2026-11-05 01:27:25 +00:00
[GH-ISSUE #56] SharePoint connector: file listing works, but file download fails on Graph :/content with 302 Found redirect #39
Labels
No labels
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
open-webui/oikb#39
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @schweitzert on GitHub (Jun 17, 2026).
Original GitHub issue: https://github.com/open-webui/oikb/issues/56
Environment
Sites.Read.All(Application), admin consent grantedDokumenteSummary
The SharePoint connector can successfully:
However, the actual file content download fails when requesting:
GET /drives/{drive-id}/root:/path/to/file:/contentMicrosoft Graph responds with:
302 Foundredirecting to a SharePoint
download.aspxURL, and oikb treats this as an error instead of following the redirect and downloading the file.As a result:
Config
What works
These steps succeed:
Token request to Entra:
POST https://login.microsoftonline.com/<tenant-id>/oauth2/v2.0/token200 OKSite lookup works
GET https://graph.microsoft.com/v1.0/sites/tenant.sharepoint.com200 OKDrive lookup works
GET https://graph.microsoft.com/v1.0/sites/{site-id}/drives200 OKFolder listing:
GET https://graph.microsoft.com/v1.0/drives/{drive-id}/root:/Test:/children200 OKOpen WebUI diff + directory creation:
POST /api/v1/knowledge/<kb-id>/sync/diff->200 OKPOST /api/v1/knowledge/<kb-id>/dirs/create->200 OKSo the connector clearly sees the folder and its files.
Actual failure
When oikb tries to fetch file content, e.g.:
GET https://graph.microsoft.com/v1.0/drives/{drive-id}/root:/Test/example.txt:/contentthe response is:
HTTP/1.1 302 Foundwith a redirect location like:
https://tenant.sharepoint.com/_layouts/15/download.aspx?UniqueId=...&tempauth=...&ApiVersion=2.0oikb then logs this as an error and skips the file.
Relevant log excerpt
Expected behavior
When Graph returns
302 Foundfor a:/contentrequest, the connector should follow the redirect (or otherwise retrieve the file content from the redirected URL) and upload the file into the Knowledge Base.Actual behavior
@Tron138 commented on GitHub (Jun 17, 2026):
When trying to download a file from SharePoint via the Microsoft Graph API, Microsoft does not return the file payload immediately. Instead, it responds with an HTTP 302 Redirect, pointing to a secure, temporary download URL (the redirect location).
The Problem:
The Python library (httpx) used by oikb for web requests is configured by default to ignore redirects. Consequently, the execution stops at the 302 Found status code instead of following the link to actually download the file.
The Solution: Applying the Redirect Fix
We can apply a quick patch directly inside the running Docker container to instruct oikb to automatically follow these download redirects.
Run the following command in your terminal to patch the code inside the container:
Bash
docker exec -it oikb-sync python -c "
import oikb.connectors.sharepoint as s
path = s.file
with open(path, 'r') as f:
code = f.read()
code = code.replace('timeout=60.0,', 'timeout=60.0,\n follow_redirects=True,')
with open(path, 'w') as f:
f.write(code)
print('--- Redirect fix successfully applied! ---')
"
@Tch1b0 commented on GitHub (Jun 17, 2026):
Just like @Tron138 described, this seems to be fixed by adding a
follow_redirects=Trueparameter here.@Tron138 commented on GitHub (Jun 17, 2026):
and if you want to make the sharepoint url like this: sharepoint.com/sites/one/AllForAi
so it only searches the folder AllForAi and subfolder. you can replace the parts = source.split("/", 1) with parts = source.rsplit("/", 1).
here is the docker quick fix,
docker exec -it <CONTAINER_NAME> python -c "
import oikb.connectors.sharepoint as s
path = s.file
with open(path, 'r') as f:
code = f.read()
code = code.replace('source.split("/", 1)', 'source.rsplit("/", 1)')
with open(path, 'w') as f:
f.write(code)
print('--- Code erfolgreich ---')
"
but then you need to make everything in the .oikb.yaml in " " like:
sources:
source: "sharepoint.com:/sites/one/Ai"
kb-id: "YOUR CODE"
interval: "1h"
@schweitzert commented on GitHub (Jun 18, 2026):
Quick update from my side:
Both workaround fixes are working for me now:
Redirect fix
Adding
follow_redirects=Truefixes the SharePoint file download problem when Microsoft Graph returns302 Foundfor:/content.Site path parsing fix
Replacing
source.split("/", 1)withsource.rsplit("/", 1)works together with a source format like:This allows syncing from a SharePoint site-based library instead of only the root-level library.
For example, this works for me now:
And the sanitized logs now show the redirect being followed successfully and the file uploaded to Open WebUI:
So from a functional point of view, both fixes solve the main issues on my side.
Questions
Right now both changes are applied as quick patches inside the running container, so they are not update-resistant.
Is there already a plan to include these fixes in an official release? And if yes, is there any rough timeline? It would be very helpful to have this supported natively, especially for site-based SharePoint / Teams document libraries.
Even with the working site-based source and a filter like:
the connector still appears to recursively scan a very large part of the SharePoint library before applying the filter.
Sanitized example log excerpts:
This makes syncs relatively slow for large SharePoint sites, because it seems to enumerate a lot of folders every time before the filter limits which files are actually uploaded.
Is there currently any recommended approach to reduce this?
For example:
This would be especially helpful for Teams-based SharePoint sites with a lot of data, where only a small subfolder should be synced.
Thanks again the current workarounds already helped a lot.