fastapi: Error getting request body: The `python-multipart` library must be installed to use form parsing.
(venv) G:\projects\python\fastprojects>pip list
python-dateutil 2.8.1 python-multipart 0.0.5 rope 0.17.0
@app.post('/token', tags=['safe'])
async def login(form_data: OAuth2PasswordRequestForm = Depends()):
print('form_data', form_data)
user_dict = fake_users_db.get(form_data.username)
if not user_dict:
raise HTTPException(
status_code=400,
detail='Incorrect username or password'
)
user = UserInDB(**user_dict)
hashed_password = fake_hash_password(form_data.password)
if not hashed_password == user.hashed_password:
raise HTTPException(
status_code=400,
detail='Incorrect username or password'
)
return {'access_token': user.username, 'token_type': 'bearer'}
I donβt know how to troubleshoot this problem
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 21 (7 by maintainers)
The error output instructs the user to install
python-multipart, instead ofmultipart.Itβs also possible that both need to be installed.
The issue is that an import exception is being swallowed up, and then an assumption is being printed to the user.
At the very least, the exception should be printed.
Thanks for the help here @Kludex ! π π
I understand you solved your problem, so thanks for reporting back and closing the issue @q98765543221 π
This problem occurs when I use a virtual environment and does not occur when I use a system environment, where the project was created using pyCharm