question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

AttributeError: 'Request' object has no attribute '_body'

See original GitHub issue

First Check

  • I added a very descriptive title to this issue.
  • I used the GitHub search to find a similar issue and didn’t find it.
  • I searched the FastAPI documentation, with the integrated search.
  • I already searched in Google “How to X in FastAPI” and didn’t find any information.
  • I already read and followed all the tutorial in the docs and didn’t find an answer.
  • I already checked if it is not related to FastAPI but to Pydantic.
  • I already checked if it is not related to FastAPI but to Swagger UI.
  • I already checked if it is not related to FastAPI but to ReDoc.

Commit to Help

  • I commit to help with one of those options 👆

Example Code

from fastapi import FastAPI
import uvicorn
app = FastAPI()

@app.get('/chain_detail/')
def read_chain_detail():    
    return 'hello world'

if __name__ == '__main__':    
    uvicorn.run(app=app, host="127.0.0.1", port=8000)

Description

I got “AttributeError ‘Request’ object has not attribute ‘_body’” error. As GET request doesn’t have body, I have no idea how can I fix it.

Operating System

Windows

Operating System Details

Windows 10 Version No. 1809

FastAPI Version

0.73.0

Python Version

3.8.8

Additional Context

No response

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:7

github_iconTop GitHub Comments

1reaction
jujumilk3commented, Feb 14, 2022

In my case there’s no problem like you. Just try to install fastAPI by use pip install "fastapi[all]

0reactions
tianzhipengfeicommented, Feb 15, 2022

Well, I think your original posted code has typing mistakes. I copied the code and ran it. It worked perfectly. See below:

from fastapi import FastAPI
import uvicorn # This line in your code just joined with the next line which is why I suggested to use uvicornapp in decorator.
app = FastAPI()


@app.get('/chain_detail/')
def read_chain_detail():
    return 'hello world'


if __name__ == '__main__':
    uvicorn.run(app=app, host="127.0.0.1", port=8000)

Oh, I got it, and modified it. Thanks for that. But it is not the point which caused the error. I just used chrome to visit http://127.0.0.1:8000/chain_detail/ . One more thing, I can see the correct response in chrome. But at the same time, I can see the error in console.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Python requests, no attribute 'body' - Stack Overflow
Python requests, no attribute 'body' · Try: request.content · I get a similar error: 'Request' object has no attribute 'content'. – Mustard Tiger....
Read more >
'WSGIRequest' object has no attribute 'body' ???
if not request.body: AttributeError: 'WSGIRequest' object has no attribute 'body'. I can reproduce this with a a minimal resource:.
Read more >
Flask Attributeerror Request Object Has No Attribute
Requestisjson returns True if certain request body contains JSON data. Attract and maybe should be used at one byte for business agility, and...
Read more >
flask.Request — Flask API - GitHub Pages
If you want to replace the request object used you can subclass this and set ... this attribute contains the username the user...
Read more >
Request and response objects — Django 4.1.4 documentation
Accessing the body attribute after reading the request with either of these ... attribute always contains the path info portion of the path,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found