!!! note This post is a thought. It's a short note that I make about someone else's content online. Learn more about the process here

Here's my thought on 💭 URL Decoding query strings or form parameters in Python | URLDecoder

In order to turn url encoded links back into links that I would find in the database of my thoughts project I need to urldecode them when they hit the api. When anything hits the api it must urlencode the links in order for them to be sent correctly as data and not get parsed as part of the url.

Here is a snippet of how I am using urlib.parse.unquote to un-encode encoded urls so that I can fetch posts from the database.

async def get_post_by_link(
    session: Session = Depends(get_session),
    link: str,
) -> PostRead:
    "get one post by link"
    link = urllib.parse.unquote(link)
    print(f'link: {link}')
    post = session.exec(select(Post).where(Post.link==link)).first()
    if not post:
        raise HTTPException(status_code=404, detail=f"Post not found for link: {link}")

    return post

This post was a thought by Waylon Walker see all my thoughts at https://waylonwalker.com/thoughts