Skip to content

📝(docs) fix resource server code snippet#2536

Open
jmaupetit wants to merge 1 commit into
mainfrom
fix-resource-server-doc
Open

📝(docs) fix resource server code snippet#2536
jmaupetit wants to merge 1 commit into
mainfrom
fix-resource-server-doc

Conversation

@jmaupetit

Copy link
Copy Markdown

Proposal

One needs to be authenticated while requesting the external API.

One needs to be authenticated while requesting the external API.
@jmaupetit jmaupetit self-assigned this Jul 23, 2026
@jmaupetit
jmaupetit requested a review from virgile-dev July 23, 2026 08:09
@jmaupetit jmaupetit added the documentation Improvements or additions to documentation label Jul 23, 2026
@coderabbitai

coderabbitai Bot commented Jul 23, 2026

Copy link
Copy Markdown

Review Change Stack

Walkthrough

The “Create a document” example in documentation/resource_server.md now passes an explicit headers dictionary to requests.post(...), containing the Bearer access token and Content-Type: application/json.

Estimated code review effort: 1 (Trivial) | ~2 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise and clearly refers to the documentation snippet being fixed.
Description check ✅ Passed The description matches the change by noting authentication is required for external API requests.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix-resource-server-doc

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with 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.

Inline comments:
In `@documentation/resource_server.md`:
- Line 90: Update the multipart upload request in the documentation example to
remove the explicit Content-Type header while preserving the Authorization
Bearer header, allowing requests to generate the correct multipart/form-data
boundary automatically.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 9c2da300-630c-4f62-9dbb-4fc228bc20e0

📥 Commits

Reviewing files that changed from the base of the PR and between 9c3bc8a and 203d9c6.

📒 Files selected for processing (1)
  • documentation/resource_server.md

"file": file,
},
format="multipart",
headers={"Authorization": f"Bearer {access_token}", "Content-Type": "application/json"},

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== locate file =="
git ls-files | grep 'documentation/resource_server.md' || true

echo "== relevant file section =="
if [ -f documentation/resource_server.md ]; then
  wc -l documentation/resource_server.md
  sed -n '70,105p' documentation/resource_server.md | cat -n
fi

echo "== search multipart/upload endpoint references =="
rg -n "files=|multipart|Content-Type|request\.data|json\(request|file" documentation/resource_server.md . --glob '!**/.git/**' --glob '!**/node_modules/**' | head -200

Repository: suitenumerique/docs

Length of output: 18930


🌐 Web query:

Python requests file parameters multipart content-type header boundary Content-Type application/json documentation

💡 Result:

When using the Python requests library, you should generally avoid manually setting the Content-Type header for multipart/form-data requests [1][2][3]. The library automatically calculates the correct Content-Type, including the necessary unique boundary string, whenever you provide the files parameter [1][2][4]. If you manually set the Content-Type header to multipart/form-data without the boundary parameter, or with a custom boundary that does not match the request body, your request will likely fail because the server will be unable to parse the multipart structure [1][5][6]. To send both JSON data and files in a single request, the standard approach is to treat the JSON payload as a file-like object within the files dictionary [7][8]. This allows you to specify its Content-Type as application/json, while the overall request remains multipart-encoded [7]: import requests import json url = 'http://example.com/upload' files = { 'file': ('filename.txt', open('filename.txt', 'rb')), 'metadata': (None, json.dumps({'key': 'value'}), 'application/json') } response = requests.post(url, files=files) In this example, the (None,...) syntax tells requests that the 'metadata' part is not a file, but a data field with an explicit MIME type [7]. If you have a strict requirement to control the boundary manually (e.g., for legacy API compatibility), you should not use the files parameter directly [9][3]. Instead, use the requests-toolbelt library, which provides a MultipartEncoder class designed for this purpose [5][9]. This allows you to generate both the body and the correct Content-Type header (including the boundary) to pass into your requests.post call [5][9].

Citations:


🌐 Web query:

requests-toolbelt package Python multipart encoding Content-Type header boundary

💡 Result:

The requests-toolbelt package provides the MultipartEncoder class, which automatically handles multipart/form-data encoding and generates the necessary boundary for your request [1][2]. When using MultipartEncoder, you must explicitly set the Content-Type header in your requests.post call using the encoder's content_type property, as the requests library will not automatically set it for you [2][3]. The encoder generates a unique boundary string, which is included in the value returned by the content_type property [1]. To use it, instantiate the MultipartEncoder with your fields and pass the encoder instance to the data parameter of your request, ensuring you set the header as follows: from requests_toolbelt import MultipartEncoder import requests # Create the encoder with your fields m = MultipartEncoder(fields={'field0': 'value', 'field1': 'file_content'}) # Post the request, using m.content_type to set the header r = requests.post('https://httpbin.org/post', data=m, headers={'Content-Type': m.content_type}) The m.content_type property dynamically constructs a string in the format multipart/form-data; boundary=<boundary_value> [1].

Citations:


Do not override the multipart Content-Type header.

This request only uploads a file and lets requests build the multipart body. Passing Content-Type: application/json mislabels the payload; keep the Bearer header and remove the explicit content type so the client can generate the correct multipart/form-data; boundary=... header.

Proposed fix
-            headers={"Authorization": f"Bearer {access_token}", "Content-Type": "application/json"},
+            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}", "Content-Type": "application/json"},
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
request in the documentation example to remove the explicit Content-Type header
while preserving the Authorization Bearer header, allowing requests to generate
the correct multipart/form-data boundary automatically.

@virgile-dev
virgile-dev requested review from lunika and qbey and removed request for virgile-dev July 23, 2026 08:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant