How to pass raw text in requests body
See original GitHub issueReproduce
I want to pass raw text to request body. But it has “422 Error: Unprocessable Entity” due to the \n
from posixpath import join
from fastapi import FastAPI
from pydantic import BaseModel
class Text2kgParams(BaseModel):
host: str
dataset: str
text: str
app = FastAPI()
@app.post("/text2kg")
async def contract(params: Text2kgParams):
endpoint = join(params.host, params.dataset)
return {"endpoint": endpoint, "text": params.text}
Description
If there is text contains \n
, it will throw the 422 error.
Environment
- OS: macOS
- FastAPI Version : 0.6.1
- Python: 3.7.6
Issue Analytics
- State:
- Created 3 years ago
- Reactions:7
- Comments:12 (6 by maintainers)
Top Results From Across the Web
How to send raw data in a POST request Python
You are still able to use raw json data for requests by just passing in json=raw_data, raw data being a string. This is...
Read more >Raw request body - HTTPie 3.2.1 (latest) docs
There are three methods for passing raw request data: piping via stdin , --raw='data' , and @/file/path . Redirected Input. The universal method...
Read more >How do I post request body with Curl? - ReqBin
To send data to the server in the POST request body, you must pass the required data to Curl using the -d or...
Read more >Accepting Raw Request Body Content in ASP.NET Core API ...
Lets start with a non-raw request, but rather with posting a string as JSON since that is very common. You can accept a...
Read more >Add a Request Body to a POST Request | API Connector
Use Cell Values in Request Bodies ... You can reference cells in the request body by wrapping your cell reference in 3 plus...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hmm, well you can create a workaround for it, here is one for inspiration
This is actually an invalid body
But with a custom route, we can make it work
Of course, it would fail, you can not use double quotes with the string that you created with double-quotes.
See, even syntax highlighting understands there is an error.
You can use an escape character
\
Or you can use single quotes instead of double quotes