Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion documentation/resource_server.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ EXTERNAL_API = {

**Endpoints:**

- `documents`: Controls `/external_api/v1.0/documents/`. Available actions: `list`, `retrieve`, `create`, `update`, `destroy`, `trashbin`, `children`, `restore`, `move`,`versions_list`, `versions_detail`, `favorite_detail`,`link_configuration`, `attachment_upload`, `media_auth`, `ai_transform`, `ai_translate`, `ai_proxy`. Always allowed actions: `favorite_list`, `duplicate`.
- `documents`: Controls `/external_api/v1.0/documents/`. Available actions: `list`, `retrieve`, `create`, `update`, `destroy`, `trashbin`, `children`, `restore`, `move`, `versions_list`, `versions_detail`, `favorite_detail`, `link_configuration`, `attachment_upload`, `media_auth`, `ai_transform`, `ai_translate`, `ai_proxy`. Always allowed actions: `favorite_list`, `duplicate`.
- `document_access`: `/external_api/v1.0/documents/{id}/accesses/`. Available actions: `list`, `retrieve`, `create`, `update`, `partial_update`, `destroy`
- `document_invitation`: Controls `/external_api/v1.0/documents/{id}/invitations/`. Available actions: `list`, `retrieve`, `create`, `partial_update`, `destroy`
- `users`: Controls `/external_api/v1.0/documents/`. Available actions: `get_me`.
Expand Down Expand Up @@ -87,6 +87,7 @@ Here is an example of a view that creates a document from a markdown file at the
"file": file,
},
format="multipart",
headers={"Authorization": f"Bearer {access_token}"},

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

rg -n -C 6 'requests\.(post|get|request)\(|format="multipart"|files=|DOCS_API' . \
  --glob '*.py' --glob '*.md'

Repository: suitenumerique/docs

Length of output: 50377


🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf '--- documentation/resource_server.md import/context ---\n'
sed -n '1,110p' documentation/resource_server.md

printf '\n--- install-only requests availability ---\n'
python3 - <<'PY'
try:
    import requests
    from requests.structures import CaseInsensitiveDict
    from io import BytesIO

    files = {"file": BytesIO(b"hello").__class__(BytesIO(b"hello"), name="readme.md")}
    req = requests.Request('POST', 'http://example.invalid/', files=files, headers={"Authorization": "Bearer token"})
    prepared = req.prepare()
    print(prepared.headers.get("Content-Type"))
    body = prepared.body
    print(isinstance(prepared.body, requests.structures.CaseInsensitiveDict))
    if body is not None and not isinstance(body, requests.models.PreparedRequest):
        # inspect header bytes without printing payload boundary
        print(body[:body.find(b"--") + 20] if isinstance(body, bytes) else str(type(body)))
except Exception as e:
    print(type(e).__name__, str(e))
PY

printf '\n--- requests.post signature ---\n'
python3 - <<'PY'
import inspect
import requests
sig = inspect.signature(requests.Session.post)
print(sig)
print(requests.Session.post.__doc__.splitlines()[:12] if requests.Session.post.__doc__ else "no doc")
PY

printf '\n--- inspect requests Session.post source line numbers ---\n'
python3 - <<'PY'
import inspect, requests
srcfile = inspect.getsourcefile(requests.Session.post)
sourcelines = inspect.getsourcelines(requests.Session.post)
print(srcfile, sourcelines[1])
PY

Repository: suitenumerique/docs

Length of output: 248


🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf '%s\n' '--- documentation/resource_server.md import/context ---'
sed -n '1,110p' documentation/resource_server.md

printf '%s\n' '--- install-only requests availability ---'
python3 - <<'PY'
try:
    import requests
    from requests.structures import CaseInsensitiveDict
    from io import BytesIO

    files = {"file": BytesIO(b"hello").__class__(BytesIO(b"hello"), name="readme.md")}
    req = requests.Request('POST', 'http://example.invalid/', files=files, headers={"Authorization": "Bearer token"})
    prepared = req.prepare()
    print(prepared.headers.get("Content-Type"))
    body = prepared.body
    print(isinstance(prepared.body, requests.structures.CaseInsensitiveDict))
    if body is not None and not isinstance(body, requests.models.PreparedRequest):
        print(body[:body.find(b"--") + 20] if isinstance(body, bytes) else str(type(body)))
except Exception as e:
    print(type(e).__name__, str(e))
PY

printf '%s\n' '--- requests.post signature ---'
python3 - <<'PY'
import inspect
import requests
sig = inspect.signature(requests.Session.post)
print(sig)
print(requests.Session.post.__doc__.splitlines()[:12] if requests.Session.post.__doc__ else "no doc")
PY

printf '%s\n' '--- inspect requests Session.post source locations ---'
python3 - <<'PY'
import inspect, requests
srcfile = inspect.getsourcefile(requests.Session.post)
sourcelines = inspect.getsourcelines(requests.Session.post)
print(srcfile, sourcelines[1])
PY

Repository: suitenumerique/docs

Length of output: 4528


Use files= for multipart uploads.

The Python Requests API does not accept a data dict or format="multipart"; these are Django test client arguments. Pass the file with files={"file": file} and remove format="multipart" so this copied snippet is valid Python code.

Proposed fix
 response = requests.post(
     f"{settings.DOCS_API}/documents/",
-    {
+    files={
         "file": file,
     },
-    format="multipart",
     headers={"Authorization": f"Bearer {access_token}"},
 )
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
headers={"Authorization": f"Bearer {access_token}"},
response = requests.post(
f"{settings.DOCS_API}/documents/",
files={
"file": file,
},
headers={"Authorization": f"Bearer {access_token}"},
)
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@documentation/resource_server.md` at line 90, Update the multipart upload
example in the documentation to use Requests’ files parameter with
files={"file": file}, and remove the unsupported format="multipart" argument
while preserving the Authorization header.

Source: MCP tools

)

response.raise_for_status()
Expand Down
Loading