Skip to main content

Posts

AssertionError: SessionMiddleware Must Be Installed

  Fixing the "AssertionError: SessionMiddleware Must Be Installed" in FastAPI This error typically occurs when you try to access  request.session  in custom middleware before the  SessionMiddleware  has been properly applied. Here's how you can resolve this issue and ensure smooth session handling in your FastAPI application. Understanding the Issue The error indicates that the  SessionMiddleware  is either not installed correctly or is being accessed too late in the middleware stack. To resolve this, you need to make sure that  SessionMiddleware  is added to the FastAPI application before any custom middleware that relies on session data. Error Example Code: Here's a simple FastAPI application that demonstrates the error setup for session middleware: from fastapi import FastAPI, Request from starlette.middleware.sessions import SessionMiddleware app = FastAPI() # Add SessionMiddleware first app.add_middleware(SessionMiddleware, secret_key = "some-random-string&q

apt-get vs apt vs yum | Debian-Based vs Red Hat-Based Linux Systems | Comparison and Differences

# Debian-Based Systems vs Red Hat-Based Systems The choice between apt-get and yum (or its modern replacement dnf) depends on the Linux distribution you are using. Each package manager is designed for specific Linux ecosystems, so there's no single "best" package manager that applies universally. Here are some considerations. # Debian-Based Systems: # Introduction Debian-Based Systems refer to Linux distributions that are built upon the Debian operating system as their foundational framework. These systems inherit the core characteristics, package management tools, and philosophies of Debian, which is known for its emphasis on free and open-source software, stability, and adherence to strict licensing standards. Popular Debian-based distributions include Ubuntu, Linux Mint, and Debian itself. # apt-get: On Debian-based systems, such as Ubuntu, `apt-get` is commonly used. However, i

Debian-Based vs Red Hat-Based Systems: A Comprehensive Comparison

# Debian-Based Systems vs Red Hat-Based Systems Debian-Based Systems and Red Hat-Based Systems are two major categories of Linux distributions, each with its own characteristics, package management systems, and philosophies. Here's a comparison between the two: # Debian-Based Systems: # Introduction Debian-Based Systems refer to Linux distributions that are built upon the Debian operating system as their foundational framework. These systems inherit the core characteristics, package management tools, and philosophies of Debian, which is known for its emphasis on free and open-source software, stability, and adherence to strict licensing standards. Popular Debian-based distributions include Ubuntu, Linux Mint, and Debian itself. 1.) Package Management: APT (Advanced Package Tool) : Debian-based systems primarily use APT for package management. Commands like apt-get (or apt ) are used

Understanding the Differences Between Column(TIMESTAMP(timezone=True)) and Column(DateTime) in SQLAlchemy

# Column(DateTime) vs Column(TIMESTAMP(timezone=True)) This article explains the differences between Column(TIMESTAMP(timezone=True)) and Column(DateTime) in SQLAlchemy. Both data types are used to store date and time values, but they differ in whether they include timezone information. The article provides guidance on when to use each data type, based on the timezone requirements of your application. Additionally, the article notes that the behavior of these data types may depend on the specific database backend being used. # Introduction Both `Column(TIMESTAMP(timezone=True))` and `Column(DateTime)` can be used to define a column in SQLAlchemy to store a date and time value. However, there are some differences between the two types of columns: # "Column(DateTime)" `Column(DateTime)` stores a date and time value without a timezone. This means that the value will be stored in the database exactly as it is provided, without any adjustmen

Fetching Data from External API and Pass it to a Component in Next.js

Fetching data from an external API is a common task in modern web development. In this article, we will be showing how to use Next.js to fetch data from an external API and pass it to a component. Step 1 : First, let's start by creating a new Next.js project. You can do this by running the following command in your terminal: npx create-next-app my-app This will create a new Next.js project with the name "my-app" in a new folder with that name., Step 2 : Next, we will install the axios library, which is a popular library for making HTTP requests. You can install it by running the following command in your terminal: npm install axios Step 3 : Now, let's create a new component in our Next.js project. In this example, we will call it "Card". This component will be responsible for displa