raise get_mysql_exception(
mysql.connector.errors.DatabaseError: 1364 (HY000): Field 'User_id' doesn't have a default value```
I get that error when trying to make a post in Postman that requires authentication.
The problem is that the ID isnt being acquired. I think there are two possible places of 'failure':
```py
payload = jwt.decode(token, SECRET_KEY, algorithms = ALGORITHM)
id: str = payload.get("user_id")```
```token_data = schemas.TokenData(id=id)```
The full code:
```py
def verify_access_token(token: str):
credentials_exception = HTTPException(status_code=status.HTTP_401_UNAUTHORIZED, detail=f'Could not validate credentials.', headers={"WWW-Authenticate": "Bearer"})
try:
payload = jwt.decode(token, SECRET_KEY, algorithms = ALGORITHM)
id: str = payload.get("user_id")
if id is None:
raise credentials_exception
token_data = schemas.TokenData(id=id)
except JWTError:
raise
return token_data```
How do I fix this?
#๐ User ID Default Value
8 messages ยท Page 1 of 1 (latest)
@odd bobcat
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
Closes after a period of inactivity, or when you send !close.
dont name your variable id
its a built in name and it will lead to confusion
maybe print payload to see what it looks like, might help you understand why it doesnt have the user_id value
that might be the source of your error tho
This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.