<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/"
    xmlns:atom="http://www.w3.org/2005/Atom" xmlns:media="http://search.yahoo.com/mrss/" version="2.0">
    <channel>
        
        <title>
            <![CDATA[ error - freeCodeCamp.org ]]>
        </title>
        <description>
            <![CDATA[ Browse thousands of programming tutorials written by experts. Learn Web Development, Data Science, DevOps, Security, and get developer career advice. ]]>
        </description>
        <link>https://www.freecodecamp.org/news/</link>
        <image>
            <url>https://cdn.freecodecamp.org/universal/favicons/favicon.png</url>
            <title>
                <![CDATA[ error - freeCodeCamp.org ]]>
            </title>
            <link>https://www.freecodecamp.org/news/</link>
        </image>
        <generator>Eleventy</generator>
        <lastBuildDate>Mon, 18 May 2026 22:35:24 +0000</lastBuildDate>
        <atom:link href="https://www.freecodecamp.org/news/tag/error/rss.xml" rel="self" type="application/rss+xml" />
        <ttl>60</ttl>
        
            <item>
                <title>
                    <![CDATA[ How to Fix Common Python Installation Errors on macOS ]]>
                </title>
                <description>
                    <![CDATA[ Python's popularity keeps growing as more developers adopt it for data science and machine learning, although it is already among the most popular programming languages.  I recently wrote an article for freeCodeCamp titled "How to Install Python on a... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/how-to-fix-python-installation-errors-on-mac/</link>
                <guid isPermaLink="false">66ba1602ad32b828c4c5be08</guid>
                
                    <category>
                        <![CDATA[ error ]]>
                    </category>
                
                    <category>
                        <![CDATA[ macOS ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Python ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Daniel Kehoe ]]>
                </dc:creator>
                <pubDate>Mon, 10 Jun 2024 22:57:27 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2024/06/python-install-errors.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>Python's popularity keeps growing as more developers adopt it for data science and machine learning, although it is already among the most popular programming languages. </p>
<p>I recently wrote an article for freeCodeCamp titled "<a target="_blank" href="https://www.freecodecamp.org/news/how-to-install-python-on-a-mac/">How to Install Python on a Mac</a>", which provides a clear guide to installing Python on macOS. </p>
<p>As a follow-up, I will discuss errors you may encounter when installing Python on macOS and how to fix them in this article.</p>
<h2 id="heading-contents"><strong>Contents</strong></h2>
<p>Here's what we'll cover here:</p>
<ul>
<li><a class="post-section-overview" href="#heading-how-to-fix-the-command-not-found-python-error">How to Fix the "command not found: python" Error</a></li>
<li><a class="post-section-overview" href="#using-an-out-of-date-python">Using an Out-of-date Python</a></li>
<li><a class="post-section-overview" href="#heading-using-the-system-python">Using the System Python</a></li>
<li><a class="post-section-overview" href="#heading-using-the-homebrew-python">Using the Homebrew Python</a></li>
<li><a class="post-section-overview" href="#heading-missing-pip">Missing Pip</a></li>
<li><a class="post-section-overview" href="#heading-pip-package-installation-errors">Pip Package Installation Errors</a></li>
<li><a class="post-section-overview" href="#heading-more-on-mac-python">More on Mac Python</a></li>
<li><a class="post-section-overview" href="#heading-conclusion">Conclusion</a></li>
</ul>
<h2 id="heading-how-to-fix-the-command-not-found-python-error">How to Fix the "command not found: python" Error</h2>
<p>You may encounter this error:</p>
<pre><code class="lang-bash">$ python ...
zsh: <span class="hljs-built_in">command</span> not found: python
</code></pre>
<p>You'll see this when trying to run Python commands in the terminal. This mostly happens because Python is yet to be installed. However, it is also possible, and more frustrating, that the Python installation is not in the Mac PATH.</p>
<p>If you only need to install and run a Python application, you can use <a target="_blank" href="https://mac.install.guide/homebrew/">Homebrew</a> to <a target="_blank" href="https://mac.install.guide/python/pipx">install Pipx</a>. This will install Python as a dependency. Pipx is a tool that allows you to install and run Python applications as standalone executables, avoiding dependency conflicts that can occur when using the standard Python package manager <a target="_blank" href="https://pip.pypa.io/en/stable/">Pip</a>.</p>
<p>If you're going to work on a programming project in Python, <a target="_blank" href="https://mac.install.guide/python/install-pyenv">install Python with Pyenv</a>, the standard Python version manager. Better yet, <a target="_blank" href="https://mac.install.guide/python/install-rye">install Python with Rye</a>, an all-in-one tool for Python installation, virtual environment management, and package installation.</p>
<p>If you're seeing the <code>zsh: command not found: python</code> error, and are certain you have already installed Python, you may need to update the <a target="_blank" href="https://mac.install.guide/python/path">Mac Python PATH</a>. You'll need to find where Python is installed on your system, which takes some sleuthing because there are multiple ways to install Python on macOS.</p>
<p>Here are the most common locations for Python on a Mac:</p>
<ol>
<li><code>/usr/bin/python3</code> is the system Python installed with Xcode Command Line Tools. This is an alias; the actual location is <code>/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/bin</code>.</li>
<li><code>/opt/homebrew/opt/python@3.12/libexec/bin/python</code> is the Homebrew Python.</li>
<li><code>/Library/Frameworks/Python.framework/Versions/3.12/bin/python3</code> is the Python installed with the official Python website installer.</li>
<li><code>/Users/username/.pyenv/shims/python</code> is the Python installed with Pyenv.</li>
<li><code>/Users/username/.rye/shims/python</code> is the Python installed with Rye.</li>
</ol>
<p>Enter the full pathname followed by <code>python --version</code> and see if you get a version number. If you do, you'll need to update your PATH by adding the Python installation path to your <code>.zprofile</code> file. For more information, see  <a target="_blank" href="https://mac.install.guide/terminal/path">Mac  PATH</a>.</p>
<p>The article <a target="_blank" href="https://mac.install.guide/python/command-not-found-python">Command not found: python</a> goes into more detail if you need more help.</p>
<h2 id="heading-using-an-out-of-date-python-version">Using an Out-of-date Python Version</h2>
<p>The current Python version is 3.12, as of October 2023. New releases of Python come yearly, typically released in October. The next version, Python 3.13, is expected in October 2024. The <a target="_blank" href="https://www.python.org/downloads/source/">newest Python version</a> is listed on the Python website.</p>
<p>Check your Mac Python version:</p>
<pre><code class="lang-bash">$ python --version
Python 3.12.4
</code></pre>
<p>You should see <code>Python 3.12.4</code> or a later version. You may not notice issues with an older Python version but it's a good idea to start any project with the newest version. The article about <a target="_blank" href="https://mac.install.guide/python/update">updating Python on Mac</a> explains how to update Python on macOS.</p>
<h2 id="heading-using-the-system-python">Using the System Python</h2>
<p>Macs no longer come with Python pre-installed. But you may have installed <a target="_blank" href="https://mac.install.guide/commandlinetools/">Xcode Command Line Tools</a> which includes Python 3.9.6, an older Python version that supports Apple development utilities.</p>
<p>Try <code>python3 --version</code> and <code>which -a python3</code> to check if Python was installed with Xcode Command Line Tools.</p>
<pre><code class="lang-bash">$ python3 --version
Python 3.9.6
$ <span class="hljs-built_in">which</span> -a python3
/usr/bin/python3
</code></pre>
<p>If you have Python 3.9.6 installed at <code>/usr/bin/python3</code>, you'll likely have the system Python installed by Xcode Command Line Tools. You can confirm this with <code>xcode-select -p</code> which will show if Xcode Command Line Tools is installed.</p>
<pre><code class="lang-bash">$  xcode-select -p
/Library/Developer/CommandLineTools
</code></pre>
<p>It's possible to <a target="_blank" href="https://mac.install.guide/python/alias-python3">alias python3 to python</a> but I would not recommend using the system Python for development. The system Python is intended for Apple utilities, not for you, so you should install Python on macOS separately if you want to run Python programs or develop in Python.</p>
<p>See my freeCodeCamp article <a target="_blank" href="https://www.freecodecamp.org/news/how-to-install-python-on-a-mac/">How to Install Python on a Mac</a> to install Python for development.</p>
<h2 id="heading-using-the-homebrew-python">Using the Homebrew Python</h2>
<p>If you use Homebrew as a software package manager, you can easily install Python with <code>brew install python</code>. Homebrew-installed Python is suitable for running scripts but it has drawbacks for installing Python applications or Python software development, when packages are installed.</p>
<ul>
<li><strong>Homebrew's automatic updates.</strong> Homebrew automatically updates its Python as a dependency for other packages, potentially breaking your projects.</li>
<li><strong>Multiple projects may need different Python versions.</strong> Homebrew-installed Python is a single version and you may need to switch among different versions for different projects.</li>
<li><strong>Problems with environment isolation.</strong> Homebrew provides a single Python environment, which can cause conflicts between projects. Pip, the Python package manager, will block installation of packages unless you first create a virtual environment.</li>
</ul>
<p>You can check if Python is installed with Homebrew:</p>
<pre><code class="lang-bash">$ brew list | grep python
python@3.12
</code></pre>
<p>For running applications, it's best to <a target="_blank" href="https://mac.install.guide/python/pipx">install Pipx</a> and use <code>pipx install</code> instead of <code>pip install</code> to install programs. For Python development, it's best to  install Pyenv or install Rye for Python version management and virtual environments.</p>
<h2 id="heading-missing-pip">Missing Pip</h2>
<p>READMEs and tutorials often assume users are familiar with Python development tools and instruct them to install Python packages using Pip, the Python package manager. If you've followed instructions that start with <code>pip install &lt;package&gt;</code>, you may have run into the <code>zsh: command not found: pip</code> error.</p>
<p>This is the error you'll see:</p>
<pre><code class="lang-bash">$ pip install &lt;package&gt;
zsh: <span class="hljs-built_in">command</span> not found: pip
</code></pre>
<p>Pip is installed automatically with Python, so it's unusual to run the <code>python</code> command successfully and then <code>pip</code> and see the error. If you have Python installed, you should be able to use the <code>pip</code> command. You can try a special command that installs Pip:</p>
<pre><code class="lang-bash">$ python -m ensurepip --upgrade
</code></pre>
<p>If Pip is not already installed, this command will install it. Otherwise, nothing will happen. With this error, it's more likely that you have a Python installation that is not in your Mac Python PATH. See the article <a target="_blank" href="https://mac.install.guide/python/command-not-found-pip">Command not found: pip</a> for more details.</p>
<h2 id="heading-pip-package-installation-errors">Pip Package Installation Errors</h2>
<p>You will need to use Pip to install Python packages, unless you are using <a target="_blank" href="https://rye.astral.sh/">Rye</a> as an all-in-one tool. However, Pip has some drawbacks.</p>
<p>By default, the <code>pip install &lt;package&gt;</code> command installs the package "globally." This means that the package is added to the global Python <code>site-packages</code> directory, which may result in conflicts if different projects require different versions of the same package. </p>
<p>For example, if project A requires <code>package==1.0</code> and project B requires <code>package==2.0</code>, installing both packages globally may result in conflicts and <a target="_blank" href="https://en.wikipedia.org/wiki/Dependency_hell">dependency hell</a>. Without proper isolation, installing one project's dependencies can cause problems for another. To avoid these conflicts, create a Python virtual environment for each project.</p>
<p>There are two Python tools for creating virtual environments and using different versions of packages. <a target="_blank" href="https://docs.python.org/3/library/venv">Venv</a> is a built-in Python package. <a target="_blank" href="https://virtualenv.pypa.io/en/latest/">Virtualenv</a> is a more powerful tool with additional features. These tools allow <code>pip</code> to install Python packages into a virtual environment that has its own installation directories and does not share libraries with other virtual environments. Pip must be used in conjunction with either Venv or Virtualenv to successfully install packages.</p>
<p>When you try to install a package with Pip, you may see:</p>
<pre><code class="lang-bash">$ pip install &lt;package&gt;
error: externally-managed-environment
</code></pre>
<p>Recent versions of <code>pip</code> implement <a target="_blank" href="https://peps.python.org/pep-0668/">PEP 668</a> to prevent attempts to install packages globally, which results in the message <a target="_blank" href="https://mac.install.guide/python/externally-managed-environment">error: externally-managed-environment</a>. This error occurs when attempting to install a package globally without using a virtual environment. To resolve this error, create a virtual environment using Venv or Virtualenv and install the package within it.</p>
<h2 id="heading-more-on-mac-python">More on Mac Python</h2>
<p>You'll need to do more than install Python to begin a programming project, so I've also written a longer article about <a target="_blank" href="https://mac.install.guide/python/">Mac Python</a> that explains the fundamentals of version management, virtual environments, and package management, as well as comparing various installation options.</p>
<h2 id="heading-conclusion">Conclusion</h2>
<p>A variety of competing development tools means that it can be difficult to get started with Python compared to other programming languages such as JavaScript, Rust, or Ruby. Python is moving towards standardization of tools, and there's rapid innovation as the community seeks to improve the developer experience.</p>
<p>For now, developing Python skills requires some knowledge of the Python ecosystem, the various tools, and how to use them. Still, Python is popular and powerful, and the tutorials on freeCodeCamp will help you learn the language and become a better developer.</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ How to Build Error-Free HTML Forms ]]>
                </title>
                <description>
                    <![CDATA[ After taking some coding courses, I decided that it was time to put my knowledge to good use and do a coding project.  Like most newbies, I went to Google to find some inspiration. As I scrolled through the internet, I stumbled upon Skillcrush’s list... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/how-to-build-error-free-html-forms/</link>
                <guid isPermaLink="false">66b904fe941d2f900bad52b6</guid>
                
                    <category>
                        <![CDATA[ error ]]>
                    </category>
                
                    <category>
                        <![CDATA[ forms ]]>
                    </category>
                
                    <category>
                        <![CDATA[ HTML ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Christine Belzie ]]>
                </dc:creator>
                <pubDate>Mon, 17 Jul 2023 18:47:31 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2023/07/FCC-Blog-Cover-4.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>After taking some coding courses, I decided that it was time to put my knowledge to good use and do a coding project. </p>
<p>Like most newbies, I went to Google to find some inspiration. As I scrolled through the internet, I stumbled upon <a target="_blank" href="https://skillcrush.com/blog/html-css-projects/">Skillcrush’s list of HTML and CSS projects for beginners</a>. </p>
<p>Number 5 piqued my interest, so I googled some images on how HTML forms should look. I thought “Oh I can do this. This looks easy!” But this project turned out to be a bit harder than I thought. </p>
<p>In this article, I will show you three things I have learned in surviving, I mean making HTML forms error-free. Let’s get started! 😀</p>
<h2 id="heading-tip-1-make-sure-the-labels-and-inputs-match">Tip #1: Make Sure the Labels and Inputs Match.</h2>
<p>When I first started creating HTML forms, I would often use the following methods for creating email input fields:</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">label</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"text"</span>&gt;</span> Your Email<span class="hljs-tag">&lt;/<span class="hljs-name">label</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"text"</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"text"</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"text"</span>&gt;</span>
</code></pre>
<p>I would often use <code>text</code> as the label and id's attribute because I thought it was the correct method. </p>
<p>This all changed when I started using <a target="_blank" href="https://wave.webaim.org/extension/">WAVE’s accessibility checker</a> to learn how to make my code more accessible. When I ran my form through the checker, it pointed out that the email input did not have a properly associated label, and that can cause screen readers to have difficulty presenting it to users with disabilities.</p>
<p>So, I googled a few sources and found <a target="_blank" href="https://css-tricks.com/html-inputs-and-labels-a-love-story/">”HTML Inputs and Labels: A Love Story” by Amber Wilson</a>. Through reading this article, I learned that it’s best to use specific names in the <code>id</code> attribute. </p>
<p>With a new feeling of confidence, I started using this approach. Here’s an example:</p>
<div class="embed-wrapper">
        <iframe width="100%" height="350" src="https://codepen.io/CB_ID2/embed/MWPPmBG" style="aspect-ratio: 16 / 9; width: 100%; height: auto;" title="CodePen embed" scrolling="no" allowtransparency="true" allowfullscreen="true" loading="lazy"></iframe></div>
<p>In the code snippet above, I used <code>email</code> as the label and input’s <code>id</code> attribute. When I ran it through the accessibility checker, there were no red Xs.  </p>
<p>While this victory was sweet, I wanted to learn more ways to ensure that labels and inputs were accessible. So I went to Google and found this <a target="_blank" href="https://www.w3schools.com/html/html_forms_attributes.asp">HTML Forms attributes article</a>. Through reading, I learned that you can add other attributes like <code>placeholder</code>, which demonstrates how the user should present their contact information.  </p>
<p>Through these experiences, I realized that creating harmonious labels and inputs for a form is like constructing a sandwich. You want to make sure that your flavors work well together and use the best features of your oven (or whatever appliance you use) to make your sandwich nice and toasty. </p>
<p>Now before we start getting hungry, let’s move on to my next tip. :) </p>
<h2 id="heading-tip-2-be-more-semantic-when-creating-a-button"><strong>Tip #2:  Be More Semantic When Creating a Button</strong></h2>
<p>Formatting your form’s buttons is crucial to the efficiency of your HTML form. Buttons are the main way that your user’s information is sent to your desired destination. </p>
<p>When I first started creating HTML forms, I used to create buttons like this:</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"submit"</span>&gt;</span>
</code></pre>
<p>Like the labels and inputs, I would get a red x on WAVE’s accessibility checker. In the results, it mentioned that a <code>value</code> attribute was missing, which makes it difficult for the screen reader to detect the button. </p>
<p>With that in mind, I decided to do what most beginners do when creating this feature: </p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">button</span>&gt;</span> Submit<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span>
</code></pre>
<p>When I ran the code in the WAVE accessibility checker again, it passed a few tests. But something inside me told me that my previous solution was ok too and that I just needed to find a way to add a <code>value</code> attribute to it.  </p>
<p>With a new thirst for knowledge, I went to Google and found this <a target="_blank" href="https://www.w3.org/WAI/tutorials/forms/labels/#labeling-buttons">article on how to create accessible form components</a>. In the section about buttons, they recommend using the following methods to make this element semantic:   </p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"Submit"</span> <span class="hljs-attr">value</span>=<span class="hljs-string">"Submit"</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"Submit"</span>&gt;</span>Submit<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span>
</code></pre>
<p>When I ran the first snippet into the accessibility checker, I received no red Xs. The same result occurred when I ran the second code snippet through the accessibility checker.  </p>
<p>At first, I didn't know which one to pick because both approaches made the form accessible. But something inside me told to go with what I truly wanted. So, I took a deep breath and chose the following code line:</p>
<div class="embed-wrapper">
        <iframe width="100%" height="350" src="https://codepen.io/CB_ID2/embed/Rwedeme" style="aspect-ratio: 16 / 9; width: 100%; height: auto;" title="CodePen embed" scrolling="no" allowtransparency="true" allowfullscreen="true" loading="lazy"></iframe></div>
<p>I decided to go with the second code snippet because it's more explicitly labeled, which makes it easier for screen readers to scan. It's also easier to remember, and is the method that I often use for creating buttons. </p>
<p>Think of it as deciding to go with the brand of bread you’ve always used for your sandwiches instead of picking a different one. As cliché as this saying sounds, sometimes simplicity is best.  </p>
<p>Before you start getting hungry again, there is just one more suggestion for making your HTML forms error-free.</p>
<h2 id="heading-tip-3-pick-the-best-css-framework-based-on-your-needs"><strong>Tip #3:  Pick the Best CSS Framework Based on Your Needs</strong></h2>
<p>When I first started creating the style for my forms, I used to force myself to use CSS frameworks like Flexbox. At the time, my feelings of imposter syndrome were at an all-time high due to seeing other people creating great forms with those frameworks. I felt that if I started using them too, I would get those same designs. </p>
<p>At first, I was happy with using Flexbox as it made things like centering content easier as shown in the snippet below:</p>
<div class="embed-wrapper">
        <iframe width="100%" height="350" src="https://codepen.io/CB_ID2/embed/mdzoQrg" style="aspect-ratio: 16 / 9; width: 100%; height: auto;" title="CodePen embed" scrolling="no" allowtransparency="true" allowfullscreen="true" loading="lazy"></iframe></div>
<p>Unfortunately, I still wasn't satisfied in the end. I found that the design did not come to fruition as I envisioned.  </p>
<p>To combat this feeling, I went to Google to find something to help me solve my dilemma. When I was about to give up, I stumbled upon the article, <a target="_blank" href="https://blog.logrocket.com/how-to-style-forms-with-css-a-beginners-guide/">“How to style forms with CSS: A beginner’s guide” by Supun Kavinda</a>.</p>
<p>My heart leaped with joy when it pointed out that you can use vanilla CSS to create beautiful designs. For example, to make the texts’ input fields look more presentable, I could do this:</p>
<pre><code class="lang-css"><span class="hljs-selector-tag">input</span><span class="hljs-selector-attr">[type=text]</span>{
<span class="hljs-attribute">padding</span>: <span class="hljs-number">10px</span>;
}
</code></pre>
<p>With newfound confidence, I gave vanilla CSS another chance, and I can honestly say I was so happy with this decision. Here’s the final result:</p>
<div class="embed-wrapper">
        <iframe width="100%" height="350" src="https://codepen.io/CB_ID2/embed/NWOOQXQ" style="aspect-ratio: 16 / 9; width: 100%; height: auto;" title="CodePen embed" scrolling="no" allowtransparency="true" allowfullscreen="true" loading="lazy"></iframe></div>
<p>I wanted to keep my design simple, so I used basic elements like <code>text-align</code>  property to center my form's content. </p>
<p>If I had to pick something that exemplifies this experience, it would be like a sandwich cut into two triangle slices. Simple yet effective.  </p>
<p>Overall, sometimes, it’s best to go back to the basics before moving on to something more challenging. </p>
<h2 id="heading-conclusion"><strong>Conclusion</strong></h2>
<p>There it is folks, my three tips on how to make your HTML forms error-free. </p>
<p>I know creating HTML forms can be frightening in the beginning. But with these tips, confidence, and some imagination, you can HTML forms that wow your viewers. Now go forth and be great! :)   </p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ ImportError: cannot import name 'force text' from 'django.utils.encoding' [Python Error Solved] ]]>
                </title>
                <description>
                    <![CDATA[ Encountering errors is very common during software development, and when working with Python and Django one such error is ImportError: cannot import name 'force text' from 'django.utils.encoding'. This particular error indicates that there is a probl... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/importerror-cannot-import-name-force-text-from-django-utils-encoding-python-error-solved/</link>
                <guid isPermaLink="false">66b8dbeff88daef58d10eef0</guid>
                
                    <category>
                        <![CDATA[ error ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Python ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Hillary Nyakundi ]]>
                </dc:creator>
                <pubDate>Tue, 27 Jun 2023 16:43:24 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2023/06/CoverImage-2.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>Encountering errors is very common during software development, and when working with Python and Django one such error is <code>ImportError: cannot import name 'force text' from 'django.utils.encoding'</code>.</p>
<p>This particular error indicates that there is a problem with importing the <code>force text</code> method from the <code>django.utils.encoding</code> module. The missing method is used for converting input data into a consistent text string format.</p>
<p>Perhaps you might wonder, what exactly caused this error even though you seem to have done everything right, well here is what might have happened: </p>
<ul>
<li>Outdated package</li>
<li>Incorrect import statement</li>
</ul>
<p>So, we know the cause but how do we solve the error? Below are a couple of steps to solve it:</p>
<h2 id="heading-step-1-update-packages-and-django">Step 1: Update Packages and Django</h2>
<p>In most cases, the error message will contain information about the package that caused the error. After confirming which one it is, follow the necessary steps to update it. </p>
<p>In most cases, to update a package in Python, you can use <code>pip install &lt;packagename&gt; --upgrade</code>, replacing the <code>packagename</code> with your desired package.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/06/force_text.png" alt="force_text" width="600" height="400" loading="lazy"></p>
<p>Another cause for an outdated package is if you are using an older version of Django. Previous versions of Django used the <code>force_text</code> method which changed to <code>force_str</code> in the newer version. So updating Django might also solve the problem.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/06/version.png" alt="version" width="600" height="400" loading="lazy"></p>
<h2 id="heading-step-2-update-import-statement">Step 2: Update Import Statement</h2>
<p>Next you'll need to confirm that the import statement is correct. The correct import statement should look like this:</p>
<pre><code class="lang-python"><span class="hljs-keyword">from</span> django.utils.encoding <span class="hljs-keyword">import</span> force_text
</code></pre>
<p>For Django 3.0 and above, it looks like this:</p>
<pre><code class="lang-python"><span class="hljs-keyword">from</span> django.utils.encoding <span class="hljs-keyword">import</span> force_str
</code></pre>
<p>Generally when working with Django, understanding the possible cause of an error will bring you one step closer to solving it. </p>
<p>Be sure to read through the error message carefully, as in most cases it points you to the correct area and how to solve the error you may encounter.</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ You're offline. Check your Connection. [How to Fix YouTube Error] ]]>
                </title>
                <description>
                    <![CDATA[ Have you ever logged on to YouTube to watch videos only to see the error, "You're offline. Check your Connection"?  This error can occur on both the YouTube website and the mobile apps for Android and iPhone. In the case of the mobile apps, you migh... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/youre-offline-check-your-connection-how-to-fix-youtube-error/</link>
                <guid isPermaLink="false">66adf2997550d4f37c2019df</guid>
                
                    <category>
                        <![CDATA[ error ]]>
                    </category>
                
                    <category>
                        <![CDATA[ youtube ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Kolade Chris ]]>
                </dc:creator>
                <pubDate>Thu, 04 May 2023 17:44:45 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2023/05/yt-error--1-.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>Have you ever logged on to YouTube to watch videos only to see the error, "You're offline. Check your Connection"? </p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/05/ss1-2.png" alt="ss1-2" width="600" height="400" loading="lazy"></p>
<p>This error can occur on both the YouTube website and the mobile apps for Android and iPhone. In the case of the mobile apps, you might get the error "You're offline. Watch downloads without a connection." </p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/05/Screenshot_20230504-105247-1.png" alt="Screenshot_20230504-105247-1" width="600" height="400" loading="lazy"></p>
<p>That's because you have videos downloaded on that mobile app. If you don’t have downloaded videos, the error message is the same as you'd see on the web version of YouTube.</p>
<p>In this article, I'll show you how to fix the error on both PC and mobile phones so you can start watching your favorite videos on YouTube once again. But before that, let's look at what causes the error.</p>
<h2 id="heading-what-well-cover">What We'll Cover</h2>
<ul>
<li><a class="post-section-overview" href="#heading-what-causes-the-youre-offline-check-your-connection-youtube-error">What Causes the "You're offline. Check your Connection." YouTube Error?</a></li>
<li><a class="post-section-overview" href="#heading-how-to-fix-the-youre-offline-check-your-connection-youtube-error">How to Fix the "You're offline. Check your Connection." YouTube Error</a></li>
<li><a class="post-section-overview" href="#heading-how-to-fix-the-youre-offline-check-your-connection-youtube-error-on-a-computer">How to Fix the "You're offline. Check your Connection." YouTube Error on a Computer</a><ul>
<li><a class="post-section-overview" href="#heading-disable-your-ad-blocker">Disable your Ad Blocker</a></li>
<li><a class="post-section-overview" href="#heading-disable-your-virtual-private-network-vpn">Disable your Virtual Private Network (VPN)</a></li>
<li><a class="post-section-overview" href="#heading-flush-your-computers-dns-in-the-command-line">Flush your Computer's DNS in the Command Line</a></li>
</ul>
</li>
<li><a class="post-section-overview" href="#heading-how-to-fix-the-youre-offline-check-your-connection-youtube-error-on-a-mobile-phone">How to Fix the "You're offline. Check your Connection." YouTube Error on a Mobile Phone</a><ul>
<li><a class="post-section-overview" href="#heading-update-the-youtube-mobile-app">Update the YouTube Mobile App </a></li>
<li><a class="post-section-overview" href="#heading-force-stop-and-clear-your-mobile-apps-cache-data">Force Stop and Clear your Mobile App's Cache Data</a></li>
</ul>
</li>
<li><a class="post-section-overview" href="#heading-conclusion">Conclusion </a></li>
</ul>
<h2 id="heading-what-causes-the-youre-offline-check-your-connection-youtube-error">What Causes the "You're offline. Check your Connection." YouTube Error?</h2>
<p>Most errors you encounter online will contain error messages that tell you what went wrong and how to fix them. </p>
<p>In the case of this error, it is related to your internet connection. That's why a part of the error message says "You're offline". Therefore, the causes include:</p>
<ul>
<li>A poor or unstable network.</li>
<li>A faulty Wi-Fi adapter connection.</li>
<li>An outdated YouTube app or browser.</li>
<li>Corrupted cache data.</li>
</ul>
<p>The other part of the error message says "Check your connection". So make sure your internet connection is stable. </p>
<p>But your internet connection may not be the only reason for this error. Read on to see other solutions you can use to fix the error.</p>
<h2 id="heading-how-to-fix-the-youre-offline-check-your-connection-youtube-error">How to Fix the "You're offline. Check your Connection." YouTube Error</h2>
<p>Since the error is network-related, some <strong>quick fixes</strong> you can try include:</p>
<ul>
<li>Make sure your internet connection is good.</li>
<li>Refresh the YouTube website or tap retry in the YouTube mobile app.</li>
<li>Refresh the YouTube mobile app.</li>
<li>Restart the YouTube mobile app.</li>
<li>Clear your browser cache.</li>
<li>Make sure your PC or mobile phone is not in airplane mode.</li>
</ul>
<p>If all of the quick fixes above fail to work, then keep reading to see other solutions you can use to fix the error on both PC and mobile. </p>
<h2 id="heading-how-to-fix-the-youre-offline-check-your-connection-youtube-error-on-a-computer">How to Fix the "You're offline. Check your Connection." YouTube Error on a Computer</h2>
<h3 id="heading-disable-your-ad-blocker">Disable your Ad Blocker</h3>
<p>Ad blockers are software programs that prevent adverts from appearing on websites. They work by blocking the code that displays ads, such as images or videos, before they can be loaded in the browser. </p>
<p>While ad blockers can improve the user experience by removing annoying and intrusive ads, they can also interfere with some website functionalities, including YouTube.</p>
<p>So, disabling the ad blocker(s) on your computer might be enough to get YouTube working again.</p>
<h3 id="heading-disable-your-virtual-private-network-vpn">Disable your Virtual Private Network (VPN)</h3>
<p>A Virtual Private Network (VPN) can interfere with websites like YouTube and cause them not to work properly due to restrictions in the virtual server's location, configuration issues, network congestion, and so on.</p>
<p>So, just like disabling ad blockers, disabling your VPN can be a solution to the error.</p>
<h3 id="heading-flush-your-computers-dns-in-the-command-line">Flush your Computer's DNS in the Command Line</h3>
<p>Sometimes, clearing your browser's cache might not be enough to get rid of corrupted cache data because the cache might be on your computer itself. </p>
<p>In that case, you need to clear your computer's cache too. And flushing your DNS gets rid of it for you.</p>
<p>To flush your PC's DNS, open CMD and run the following commands one by one:</p>
<ul>
<li><code>ipconfig /flushdns</code></li>
<li><code>ipconfig /release</code></li>
<li><code>ipconfig /renew</code></li>
</ul>
<h2 id="heading-how-to-fix-the-youre-offline-check-your-connection-youtube-error-on-a-mobile-phone">How to Fix the "You're offline. Check your Connection." YouTube Error on a Mobile Phone</h2>
<h3 id="heading-update-the-youtube-mobile-app">Update the YouTube Mobile App</h3>
<p>If you use an Android device, head over to the Play Store and update the YouTube app if updates are available. And if you use an iPhone, you can download the latest version of the YouTube app on the iOS App Store.</p>
<p>But sometimes, the error occurs even if your mobile app is up to date. In that case, the next solution might fix it for you.</p>
<h3 id="heading-force-stop-and-clear-your-mobile-apps-cache-data">Force Stop and Clear your Mobile App's Cache Data</h3>
<p>On an Android phone, long-tap the YouTube app and select "App info":
<img src="https://www.freecodecamp.org/news/content/images/2023/05/Screenshot_20230504-115912-1.png" alt="Screenshot_20230504-115912-1" width="600" height="400" loading="lazy"></p>
<p>Tap on "Force stop":
<img src="https://www.freecodecamp.org/news/content/images/2023/05/Screenshot_20230504-1159361.png" alt="Screenshot_20230504-1159361" width="600" height="400" loading="lazy"></p>
<p>After that, select "Storage &amp; Cache":
<img src="https://www.freecodecamp.org/news/content/images/2023/05/Screenshot_20230504-115936-1.png" alt="Screenshot_20230504-115936-1" width="600" height="400" loading="lazy"></p>
<p>Tap on "Clear cache":
<img src="https://www.freecodecamp.org/news/content/images/2023/05/Screenshot_20230504-1159361-1.png" alt="Screenshot_20230504-1159361-1" width="600" height="400" loading="lazy"></p>
<p>If that fails to work, select "Clear storage" or reinstall the YouTube app.</p>
<p>On an iPhone, you can delete and reinstall the YouTube app and the cache data will go away.</p>
<h2 id="heading-conclusion">Conclusion</h2>
<p>This article showed you how to fix the YouTube error, "You're offline. Check your Connection." error on both the web version of YouTube and the mobile apps.</p>
<p>Some of the quick fixes might be enough to fix the error. But sometimes, fixing the error goes beyond those quick fixes. That's why I discussed other advanced fixes for the error.</p>
<p>Thank you for reading. If you found the article helpful, don’t hesitate to share it with your family and friends.</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ ModuleNotFoundError: no module named 'requests' [Solved in Python Django] ]]>
                </title>
                <description>
                    <![CDATA[ By Shittu Olumide Errors are an inevitable part of programming, and every programmer will encounter them at some point in their career.  Errors in programming can take various forms, including syntax errors, logic errors, and runtime errors, and they... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/python-module-not-found-error-solved/</link>
                <guid isPermaLink="false">66d4612fc7632f8bfbf1e4c3</guid>
                
                    <category>
                        <![CDATA[ Django ]]>
                    </category>
                
                    <category>
                        <![CDATA[ error ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Python ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Mon, 17 Apr 2023 23:55:53 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2023/04/Shittu-Olumide-ModuleNotFoundError-no-module-named--requests---Solved-in-Python-Django-.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>By Shittu Olumide</p>
<p>Errors are an inevitable part of programming, and every programmer will encounter them at some point in their career. </p>
<p>Errors in programming can take various forms, including syntax errors, logic errors, and runtime errors, and they can have a significant impact on the functioning of a program.</p>
<p>Understanding the different types of errors in programming and learning how to identify and fix them is essential for writing robust and reliable code. </p>
<p>In this regard, various tools, such as debuggers, profilers, and automated testing frameworks can help you detect and fix errors more efficiently.</p>
<p>In this quick tutorial, we'll look at a specific Python error – the "<code>ModuleNotFoundError: no module named 'requests'</code>" error – to see what causes it and how to fix it.</p>
<h2 id="heading-what-is-the-modulenotfounderror-no-module-named-requests-python-error">What is the <code>ModuleNotFoundError: no module named 'requests'</code> Python Error?</h2>
<p>The <code>ModuleNotFoundError: no module named 'requests'</code> error occurs when you try to import the <code>requests</code> module in your Python code but the module is not installed or not available in the current environment. </p>
<p>This error is commonly encountered when using Python Django because the <code>requests</code> module is often used for making HTTP requests in Django applications.</p>
<h2 id="heading-how-to-fix-the-modulenotfounderror-no-module-named-requests-error-in-python">How to Fix the <code>ModuleNotFoundError: no module named 'requests'</code> Error in Python</h2>
<p>To solve this error, you can follow these steps:</p>
<p>First, check if the <code>requests</code> module is installed. Open a terminal or command prompt and enter the following command:</p>
<pre><code class="lang-bash">pip freeze | grep requests
</code></pre>
<p>This command will search for the <code>requests</code> module in your environment and print its version number if it is installed. If nothing is printed, it means that the module is not installed.</p>
<p>If the <code>requests</code> module is not installed, you can install it by running the following command in your terminal or command prompt:</p>
<pre><code class="lang-bash">pip install requests
</code></pre>
<p>This command will download and install the <code>requests</code> module and all its dependencies.</p>
<p>Then you'll need to check if the <code>requests</code> module was imported correctly. Once the <code>requests</code> module is installed, you can import it in your Python code using the following statement:</p>
<pre><code class="lang-py"><span class="hljs-keyword">import</span> requests
</code></pre>
<p>Make sure that this statement is placed at the top of your Python file before any other statements that use the <code>requests</code> module.</p>
<p>Finally, if you are using the <code>requests</code> module in a Python Django application, you may need to restart your server after installing the module to ensure that the changes take effect.</p>
<h2 id="heading-wrapping-up">Wrapping Up</h2>
<p>By following these steps, you should be able to solve the <code>ModuleNotFoundError: no module named 'requests'</code> error and use the <code>requests</code> module in your Python Django application.</p>
<p>And that is it!</p>
<p>Feel free to connect with me on <a target="_blank" href="https://www.twitter.com/Shittu_Olumide_">Twitter</a> and on <a target="_blank" href="https://www.linkedin.com/in/olumide-shittu">LinkedIn</a>. You can also subscribe to my <a target="_blank" href="https://www.youtube.com/channel/UCNhFxpk6hGt5uMCKXq0Jl8A">YouTube</a> channel.</p>
<p>Happy Coding!</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ Common Errors in Python and How to Fix Them ]]>
                </title>
                <description>
                    <![CDATA[ Python is a popular programming language that is easy to learn and use. But like any programming language, Python is prone to errors. In this tutorial, we'll cover some of the most common errors in Python and how to fix them. Syntax Errors in Python ... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/common-errors-in-python-and-how-to-fix-them/</link>
                <guid isPermaLink="false">66d46091f855545810e934bd</guid>
                
                    <category>
                        <![CDATA[ error ]]>
                    </category>
                
                    <category>
                        <![CDATA[ error handling ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Python ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Jeremiah Oluseye ]]>
                </dc:creator>
                <pubDate>Mon, 13 Mar 2023 19:07:43 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2023/03/errors.JPG" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>Python is a popular programming language that is easy to learn and use. But like any programming language, Python is prone to errors.</p>
<p>In this tutorial, we'll cover some of the most common errors in Python and how to fix them.</p>
<h2 id="heading-syntax-errors-in-python">Syntax Errors in Python</h2>
<p>Syntax errors occur when you have a typo or other mistake in your code that causes it to be invalid syntax. These errors are usually caught by Python's interpreter when you try to run the code.</p>
<p>Here are some tips for avoiding syntax errors:</p>
<ul>
<li><p>Double-check your code for typos or other mistakes before running it.</p>
</li>
<li><p>Use a code editor that supports syntax highlighting to help you catch syntax errors.</p>
</li>
<li><p>Read the error message carefully to determine the location of the error.</p>
</li>
</ul>
<p>Example:</p>
<pre><code class="lang-python"><span class="hljs-keyword">if</span> x = <span class="hljs-number">10</span>:
    print(<span class="hljs-string">"x is equal to 10"</span>)
</code></pre>
<p>In this example, we are trying to assign the value 10 to the variable x using the assignment operator (=) inside an if statement.</p>
<p>But the correct syntax for comparing values in an if statement is to use the comparison operator (==).</p>
<p>So here's how you fix this one:</p>
<pre><code class="lang-python"><span class="hljs-keyword">if</span> x == <span class="hljs-number">10</span>:
    print(<span class="hljs-string">"x is equal to 10"</span>)
</code></pre>
<h2 id="heading-indentation-errors-in-python">Indentation Errors in Python</h2>
<p>One of the most common errors in Python is indentation errors. Unlike many other programming languages, Python uses whitespace to indicate blocks of code, so proper indentation is critical.</p>
<p>Here are a few rules to keep in mind when it comes to indentation in Python:</p>
<ul>
<li><p>Use four spaces for each level of indentation.</p>
</li>
<li><p>Don't mix tabs and spaces for indentation.</p>
</li>
<li><p>Make sure your indentation is consistent throughout your code.</p>
</li>
</ul>
<p>To avoid indentation errors, it's a good idea to use a code editor that supports automatic indentation, such as PyCharm or Visual Studio Code.</p>
<p>Example:</p>
<pre><code class="lang-python"><span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> range(<span class="hljs-number">10</span>):
print(i)
</code></pre>
<p>In this example, the code inside the for loop is not indented correctly.</p>
<p>Fix:</p>
<pre><code class="lang-python"><span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> range(<span class="hljs-number">10</span>):
    print(i)
</code></pre>
<h2 id="heading-name-errors-in-python">Name Errors in Python</h2>
<p>Name errors occur when you try to use a variable or function that hasn't been defined. For example, if you try to print the value of a variable that hasn't been assigned a value yet, you'll get a name error.</p>
<p>Here are some tips for avoiding name errors:</p>
<ul>
<li><p>Make sure you've defined all variables and functions before using them.</p>
</li>
<li><p>Double-check the spelling and capitalization of your variable and function names.</p>
</li>
<li><p>Use Python's built-in debugging tools, such as <code>print</code> statements, to help you track down name errors.</p>
</li>
</ul>
<p>Example:</p>
<pre><code class="lang-python">my_variable = <span class="hljs-number">5</span>
print(my_vairable)
</code></pre>
<p>In this example, we misspelled the variable name my_variable as my_vairable.</p>
<p>Fix:</p>
<pre><code class="lang-python">my_variable = <span class="hljs-number">5</span>
print(my_variable)
</code></pre>
<h2 id="heading-type-errors-in-python">Type Errors in Python</h2>
<p>Another common error in Python is type errors. Type errors occur when you try to perform an operation on data of the wrong type. For example, you might try to add a string and a number, or you might try to access an attribute of an object that doesn't exist.</p>
<p>Here are some tips for avoiding type errors:</p>
<ul>
<li><p>Use type annotations in your code to make it clear what types of data you expect.</p>
</li>
<li><p>Use Python's built-in type-checking tools, such as the <code>typing</code> module and the <code>mypy</code> tool.</p>
</li>
<li><p>Write unit tests to ensure that your code handles different types of data correctly.</p>
</li>
</ul>
<p>Example:</p>
<pre><code class="lang-python">x = <span class="hljs-string">"5"</span>
y = <span class="hljs-number">10</span>
result = x + y
</code></pre>
<p>In this example, we are trying to concatenate a string and an integer, which is not possible.</p>
<p>Fix:</p>
<pre><code class="lang-python">x = <span class="hljs-string">"5"</span>
y = <span class="hljs-number">10</span>
result = int(x) + y
</code></pre>
<p>Here, we convert the string to an integer using the int() function before performing the addition.</p>
<h2 id="heading-index-errors-in-python">Index Errors in Python</h2>
<p>Index errors occur when you try to access an item in a list or other sequence using an index that is out of range. For example, if you try to access the fifth item in a list that only has four items, you'll get an index error.</p>
<p>Here are some tips for avoiding index errors:</p>
<ul>
<li><p>Make sure you're using the correct index values for your sequence.</p>
</li>
<li><p>Use Python's built-in functions, such as <code>len</code>, to determine the length of your sequence before trying to access items in it.</p>
</li>
<li><p>Use exception handling, such as <code>try</code> and <code>except</code> blocks, to handle index errors gracefully.</p>
</li>
</ul>
<p>Example:</p>
<pre><code class="lang-python">my_list = [<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>, <span class="hljs-number">4</span>]
print(my_list[<span class="hljs-number">5</span>])
</code></pre>
<p>In this example, we are trying to access an item at index 5, which is outside the range of the list.</p>
<p>Fix:</p>
<pre><code class="lang-python">my_list = [<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>, <span class="hljs-number">4</span>]
print(my_list[<span class="hljs-number">3</span>])
</code></pre>
<p>Here, we access the item at index 3, which is within the range of the list.</p>
<h2 id="heading-key-errors-in-python">Key Errors in Python</h2>
<p>Key errors occur when you try to access a dictionary using a key that doesn't exist. For example, if you try to access the value associated with a key that hasn't been defined in a dictionary, you'll get a key error.</p>
<p>Here are some tips for avoiding key errors:</p>
<ul>
<li><p>Make sure you're using the correct keys for your dictionary.</p>
</li>
<li><p>Use Python's built-in <code>in</code> operator to check whether a key exists in a dictionary before trying to access it.</p>
</li>
<li><p>Use exception handling, such as <code>try</code> and <code>except</code> blocks, to handle key errors gracefully.</p>
</li>
</ul>
<p>Example:</p>
<pre><code class="lang-python">my_dict = {<span class="hljs-string">"name"</span>: <span class="hljs-string">"John"</span>, <span class="hljs-string">"age"</span>: <span class="hljs-number">25</span>}
print(my_dict[<span class="hljs-string">"gender"</span>])
</code></pre>
<p>In this example, we are trying to access the value for the key "gender", which does not exist in the dictionary.</p>
<p>Fix:</p>
<pre><code class="lang-python">my_dict = {<span class="hljs-string">"name"</span>: <span class="hljs-string">"John"</span>, <span class="hljs-string">"age"</span>: <span class="hljs-number">25</span>}
print(my_dict.get(<span class="hljs-string">"gender"</span>, <span class="hljs-string">"Key not found"</span>))
</code></pre>
<p>Here, we use the <code>get()</code> method to access the value for the key "gender". The second argument of the <code>get()</code> method specifies the default value to return if the key does not exist.</p>
<h2 id="heading-attribute-errors-in-python">Attribute Errors in Python</h2>
<p>Attribute errors occur when you try to access an attribute of an object that doesn't exist, or when you try to access an attribute in the wrong way.</p>
<p>There are several different types of attributes in Python:</p>
<ul>
<li><p>Instance attributes: These are attributes that belong to a specific instance of a class.</p>
</li>
<li><p>Class attributes: These are attributes that belong to a class rather than an instance.</p>
</li>
<li><p>Static attributes: These are attributes that belong to a class, but can be accessed without creating an instance of the class.</p>
</li>
</ul>
<p>To avoid attribute errors, it's important to understand the different types of attributes and how they work. You should also make sure that you're accessing attributes in the correct way, and that you're not trying to access attributes that don't exist.</p>
<p>Example:</p>
<pre><code class="lang-python">my_list = [<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>, <span class="hljs-number">4</span>]
my_list.append(<span class="hljs-number">5</span>)
my_list.add(<span class="hljs-number">6</span>)
</code></pre>
<p>In this example, we are trying to add an item to the list using the <code>add()</code> method, which does not exist for lists.</p>
<p>Fix:</p>
<pre><code class="lang-python">my_list = [<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>, <span class="hljs-number">4</span>]
my_list.append(<span class="hljs-number">5</span>)
</code></pre>
<p>Here, we use the <code>append()</code> method to add an item to the list.</p>
<h2 id="heading-general-tips">General Tips</h2>
<p>Here are a few general tips for avoiding common errors in Python:</p>
<ul>
<li><p>Use good coding practices, such as commenting your code and following the DRY (Don't Repeat Yourself) principle.</p>
</li>
<li><p>Write unit tests to catch errors before they make it into your production code.</p>
</li>
<li><p>Read the documentation for the modules and functions you're using to make sure you're using them correctly.</p>
</li>
</ul>
<h2 id="heading-conclusion">Conclusion</h2>
<p>Python is a powerful language with many features, but like any programming language, it can be prone to errors.</p>
<p>In this article, we covered some of the most common errors in Python and how to fix them. By understanding these errors and how to fix them, you can become a more confident and effective Python programmer.</p>
<p>Let’s connect on <a target="_blank" href="https://twitter.com/Olujerry19">Twitter</a> and <a target="_blank" href="https://www.linkedin.com/in/jeremiah-oluseye-58457719a/">LinkedIn</a>.</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ Circular Reference Error in JavaScript – Meaning and How to Fix It ]]>
                </title>
                <description>
                    <![CDATA[ By Dillion Megida Have you ever encountered a "circular reference" error when working with JSON?  In this tutorial, I'll explain what this error means as well as how to fix it. This error, in my experience, occurs when you try to convert an object wi... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/circular-reference-in-javascript-explained/</link>
                <guid isPermaLink="false">66d84eda29e30bc0ad477567</guid>
                
                    <category>
                        <![CDATA[ error ]]>
                    </category>
                
                    <category>
                        <![CDATA[ JavaScript ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Tue, 07 Mar 2023 21:52:14 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2023/03/22.-circular-reference-error.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>By Dillion Megida</p>
<p>Have you ever encountered a "circular reference" error when working with JSON? </p>
<p>In this tutorial, I'll explain what this error means as well as how to fix it.</p>
<p>This error, in my experience, occurs when you try to convert an object with circular references to JSON. You may have experienced this error while doing this or something else.</p>
<p>First, let's understand what a circular reference is in JavaScript.</p>
<h2 id="heading-what-is-a-circular-reference-in-js">What is a Circular Reference in JS?</h2>
<p>An object in JavaScript can have different data types for properties. Here's an example of an object:</p>
<pre><code class="lang-js"><span class="hljs-keyword">const</span> obj = {
  <span class="hljs-attr">name</span>: <span class="hljs-string">"Dillion"</span>,
  <span class="hljs-attr">isDev</span>: <span class="hljs-literal">true</span>,
  <span class="hljs-attr">hobbies</span>: [<span class="hljs-string">"singing"</span>, <span class="hljs-string">"writing"</span>],
  <span class="hljs-attr">age</span>: <span class="hljs-number">100</span>,
}
</code></pre>
<p>This object has properties containing values of the string, boolean, array, and number data type.</p>
<p>In objects, you can also have a nested object. Here's what I mean:</p>
<pre><code class="lang-js">obj.languages = {
  <span class="hljs-attr">first</span>: <span class="hljs-string">"javascript"</span>,
  <span class="hljs-attr">second</span>: <span class="hljs-string">"java"</span>,
}

<span class="hljs-built_in">console</span>.log(obj)
<span class="hljs-comment">// {</span>
<span class="hljs-comment">//   name: "Dillion",</span>
<span class="hljs-comment">//   isDev: true,</span>
<span class="hljs-comment">//   hobbies: ["singing", "writing"],</span>
<span class="hljs-comment">//   age: 100,</span>
<span class="hljs-comment">//   languages: {</span>
<span class="hljs-comment">//     first: "javascript",</span>
<span class="hljs-comment">//     second: "java"</span>
<span class="hljs-comment">//   }</span>
<span class="hljs-comment">// }</span>
</code></pre>
<p>Here, we add a <code>languages</code> property, which holds an object value containing the <code>first</code> and <code>second</code> properties.</p>
<p>To access the properties of the nested object, you can use the dot notation (or <a target="_blank" href="https://www.freecodecamp.org/news/dot-notation-vs-square-brackets-javascript/">bracket notation</a>) like this:</p>
<pre><code class="lang-js">obj.languages.first
obj.languages.second
</code></pre>
<p>I have a <a target="_blank" href="https://youtu.be/EaHC3QfU1NY">video version of this topic</a> you can also check out.</p>
<p>Now, what if we have a nested object that points to the original object? Take a look at this example:</p>
<pre><code class="lang-js">obj.itself = obj
</code></pre>
<p>Here, we add an <code>itself</code> property, and assign it an object reference, which is <code>obj</code>. This is a <strong>circular reference</strong>. I'll show you why it is called a circular reference.</p>
<p>Let's try to print <code>obj</code> to the console:</p>
<pre><code class="lang-js"><span class="hljs-comment">// {</span>
<span class="hljs-comment">//   name: "Dillion",</span>
<span class="hljs-comment">//   isDev: true,</span>
<span class="hljs-comment">//   hobbies: ["singing", "writing"],</span>
<span class="hljs-comment">//   age: 100,</span>
<span class="hljs-comment">//   languages: {</span>
<span class="hljs-comment">//     first: "javascript",</span>
<span class="hljs-comment">//     second: "java"</span>
<span class="hljs-comment">//   },</span>
<span class="hljs-comment">//   itself: [Circular *1]</span>
<span class="hljs-comment">// }</span>
</code></pre>
<p>In the console, the value of the <code>itself</code> property shows <strong>[Circular *1]</strong>. This is a notation that the property points back to the object, and trying to log the value of that property will result in an endlessly nested object.</p>
<p>This means that the <code>itself</code> property will look like this:</p>
<pre><code class="lang-js">{
  <span class="hljs-attr">name</span>: <span class="hljs-string">"Dillion"</span>,
  <span class="hljs-attr">isDev</span>: <span class="hljs-literal">true</span>,
  <span class="hljs-attr">hobbies</span>: [<span class="hljs-string">"singing"</span>, <span class="hljs-string">"writing"</span>],
  <span class="hljs-attr">age</span>: <span class="hljs-number">100</span>,
  <span class="hljs-attr">languages</span>: {
    <span class="hljs-attr">first</span>: <span class="hljs-string">"javascript"</span>,
    <span class="hljs-attr">second</span>: <span class="hljs-string">"java"</span>
  },
  <span class="hljs-attr">itself</span>: {
    <span class="hljs-attr">name</span>: <span class="hljs-string">"Dillion"</span>,
    <span class="hljs-attr">isDev</span>: <span class="hljs-literal">true</span>,
    <span class="hljs-attr">hobbies</span>: [<span class="hljs-string">"singing"</span>, <span class="hljs-string">"writing"</span>],
    <span class="hljs-attr">age</span>: <span class="hljs-number">100</span>,
    <span class="hljs-attr">languages</span>: {
      <span class="hljs-attr">first</span>: <span class="hljs-string">"javascript"</span>,
      <span class="hljs-attr">second</span>: <span class="hljs-string">"java"</span>
    },
    <span class="hljs-attr">itself</span>: {
      <span class="hljs-attr">name</span>: <span class="hljs-string">"Dillion"</span>,
      <span class="hljs-comment">// ...</span>
    }
  }
}
</code></pre>
<p>Here's a graphical illustration of this:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/03/image-54.png" alt="Image" width="600" height="400" loading="lazy">
<em>Graphical illustration of a cyclic reference</em></p>
<p>As you can see in this object, the <code>itself</code> property has all the properties of the object, including <code>itself</code>, which again has all the properties of the object, including <code>itself</code> and it keeps going on and on without any end.</p>
<p>With this circular reference of the property to the object, we can access the <code>first</code> property like this:</p>
<pre><code class="lang-js">obj.itself.itself.itself.itself.itself.itself.first
</code></pre>
<p>This many <code>itself</code>s still work due to circular reference.</p>
<p>We can also access the <code>name</code> property in <code>obj</code> like this:</p>
<pre><code class="lang-js">obj.itself.itself.itself.itself.name
</code></pre>
<p>Since <code>itself</code> has a reference to <code>obj</code>, we can access the <code>name</code> property from any of the nested <code>itself</code>s.</p>
<p>Now let's see how this circular reference pattern applies to JSON.</p>
<h2 id="heading-jsons-issue-with-circular-references">JSON's Issue with Circular References</h2>
<p>Let's look at our initial object again:</p>
<pre><code class="lang-js"><span class="hljs-keyword">const</span> obj = {
  <span class="hljs-attr">name</span>: <span class="hljs-string">"Dillion"</span>,
  <span class="hljs-attr">isDev</span>: <span class="hljs-literal">true</span>,
  <span class="hljs-attr">hobbies</span>: [<span class="hljs-string">"singing"</span>, <span class="hljs-string">"writing"</span>],
  <span class="hljs-attr">age</span>: <span class="hljs-number">100</span>,
}
</code></pre>
<p>When you stringify this object to fit the JSON structure, here's the result:</p>
<pre><code class="lang-js"><span class="hljs-keyword">const</span> stringified = <span class="hljs-built_in">JSON</span>.stringify(obj)

<span class="hljs-built_in">console</span>.log(stringified)
<span class="hljs-comment">// {</span>
<span class="hljs-comment">//   "name":"Dillion",</span>
<span class="hljs-comment">//   "isDev":true,</span>
<span class="hljs-comment">//   "hobbies":["singing","writing"],"age":100</span>
<span class="hljs-comment">// }</span>
</code></pre>
<p>JSON stringify goes through the properties from the first one being "name" to the last one being "hobbies".</p>
<p>What if we had our nested <code>languages</code> object stringified?</p>
<pre><code class="lang-js">obj.languages = {
  <span class="hljs-attr">first</span>: <span class="hljs-string">"javascript"</span>,
  <span class="hljs-attr">second</span>: <span class="hljs-string">"java"</span>,
}

<span class="hljs-keyword">const</span> stringified = <span class="hljs-built_in">JSON</span>.stringify(obj)

<span class="hljs-built_in">console</span>.log(stringified)
<span class="hljs-comment">// {</span>
<span class="hljs-comment">//   "name":"Dillion",</span>
<span class="hljs-comment">//   "isDev":true,</span>
<span class="hljs-comment">//   "hobbies":["singing","writing"],"age":100,</span>
<span class="hljs-comment">//   "languages":{</span>
<span class="hljs-comment">//     "first":"javascript",</span>
<span class="hljs-comment">//     "second":"java"</span>
<span class="hljs-comment">//   }</span>
<span class="hljs-comment">// }</span>
</code></pre>
<p>As you see here, the stringify method goes through the properties from the first one being "name" to the last one being "languages". When it gets to languages, it goes through the properties of the object which are <code>first</code> and <code>second</code>.</p>
<p>Now let's introduce a circular reference and see what happens:</p>
<pre><code class="lang-js">obj.itself = obj

<span class="hljs-keyword">const</span> stringified = <span class="hljs-built_in">JSON</span>.stringify(obj)

<span class="hljs-built_in">console</span>.log(stringified)
<span class="hljs-comment">// TypeError: Converting circular structure to JSON</span>
</code></pre>
<p>Now we get an error: <strong>TypeError: Converting circular structure to JSON</strong>.</p>
<p>What's the problem here?</p>
<p>By stringifying an object with a circular reference, that's an infinite stringification process.</p>
<p>Let's say JSON stringify tried to go through this object, here's what happens: the stringify method goes from the first property in <code>obj</code> which is <code>name</code> to the last property <code>itself</code>. When it gets to <code>itself</code>, it stringifies the properties of this object. The value of the <code>itself</code> object is the <code>obj</code> object, so stringify goes through from <code>name</code> to <code>itself</code> again. By coming across <code>itself</code>, it has to go through again.</p>
<p>Here's an illustration explaining what happens:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/03/image-55.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>As you see here, this results in an infinite loop because <code>stringify</code> doesn't know when to stop. Everytime it comes across <code>itself</code>, it has to go through this object that has <code>itself</code>. It will keep stringifying forever.</p>
<p>This is basically impossible. So when the stringify method comes across a circular reference in an object, it just throws an error immediately. There's no need to waste its time 😅</p>
<p>So if you come across this error when building applications, how do you solve it?</p>
<h2 id="heading-how-to-solve-the-circular-reference-error">How to Solve the Circular Reference Error</h2>
<p>There are a couple of ways you can solve this problem. You can use libraries or implement a solution yourself.</p>
<p>One major way to solve this is by using <strong>serialization</strong>. This process involves serializing the object to remove some properties from an object before converting it to JSON. </p>
<p>In this process, you can remove properties you are not interested in, or in our case, properties that can cause errors.</p>
<p>Here's a simple solution:</p>
<pre><code class="lang-js">obj.itself = obj

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">replacer</span>(<span class="hljs-params">key, value</span>) </span>{
  <span class="hljs-keyword">if</span>(key === <span class="hljs-string">'itself'</span>) {
    <span class="hljs-keyword">return</span> <span class="hljs-literal">null</span>
  }

  <span class="hljs-keyword">return</span> value
}

<span class="hljs-keyword">const</span> stringified = <span class="hljs-built_in">JSON</span>.stringify(obj, replacer)

<span class="hljs-built_in">console</span>.log(stringified)
<span class="hljs-comment">// {</span>
<span class="hljs-comment">//   "name":"Dillion",</span>
<span class="hljs-comment">//   "isDev":true,</span>
<span class="hljs-comment">//   "hobbies":["singing","writing"],"age":100,</span>
<span class="hljs-comment">//   "languages":{</span>
<span class="hljs-comment">//     "first":"javascript",</span>
<span class="hljs-comment">//     "second":"java"</span>
<span class="hljs-comment">//   },</span>
<span class="hljs-comment">//   "itself":null</span>
<span class="hljs-comment">// }</span>
</code></pre>
<p>What we've done here is use the <a target="_blank" href="https://dillionmegida.com/p/second-argument-in-json-stringify/">replacer argument of JSON.stringify</a> to modify the <code>itself</code> property.</p>
<p>In the replacer function, we check for the key <code>itself</code>, and return the value <code>null</code> for that key. This way, <code>JSON.stringify</code> replaces the circular reference value with <code>null</code> during stringifying, thereby avoiding infinite stringification.</p>
<h2 id="heading-wrapping-up">Wrapping Up</h2>
<p>If you build applications with JavaScript, you may have come across this cyclic reference error one way or the other.</p>
<p>In this article, I've explained what this error is, and why it exists when converting an object to JSON.</p>
<p>If you enjoyed this article, please share it with others 🙏🏾</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ Microsoft Excel – How to Use Data Validation and Conditional Formatting to Prevent Errors ]]>
                </title>
                <description>
                    <![CDATA[ I've been using Microsoft Excel and Google Sheets in my business for over a decade. And as I've learned better ways to clean and validate data, it's increased productivity, decreased human errors, and generally caused a lot of joy! 🥳 In this article... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/excel-use-data-validation-and-conditional-formatting-to-prevent-errors/</link>
                <guid isPermaLink="false">66b8dde4d68a0821bf8c474a</guid>
                
                    <category>
                        <![CDATA[ error ]]>
                    </category>
                
                    <category>
                        <![CDATA[ excel ]]>
                    </category>
                
                    <category>
                        <![CDATA[ spreadsheets ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Eamonn Cottrell ]]>
                </dc:creator>
                <pubDate>Mon, 06 Mar 2023 16:41:05 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2023/03/fcc.jpg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>I've been using Microsoft Excel and Google Sheets in my business for over a decade. And as I've learned better ways to clean and validate data, it's increased productivity, decreased human errors, and generally caused a lot of joy! 🥳</p>
<p>In this article, we'll look at two ways to validate and/or apply conditional formatting to a sample order form to prevent errors and speed up fulfillment.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/03/no-error.gif" alt="Image" width="600" height="400" loading="lazy">
<em>gif of man saying, "there is no room for error"</em></p>
<p>You can find the Excel sheet we're using for this tutorial <a target="_blank" href="https://onedrive.live.com/edit.aspx?resid=FE6EDAF51E9AF322!1141&amp;ithint=file%2Cxlsx&amp;authkey=!ANRcKMn_p25YVyo">here</a>. </p>
<p>You may download a local copy to tinker with by selecting <code>File, Save As, Download a Copy</code>:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/03/image-21.png" alt="Image" width="600" height="400" loading="lazy">
<em>Download a copy of Excel Workbook</em></p>
<p>You can find a Google Sheets version of the same thing <a target="_blank" href="https://docs.google.com/spreadsheets/d/1gnacOaU_TCX_I7wGxHWWriyej4kI7t9AzM_nLybv9Cs/edit?usp=sharing">here</a>.</p>
<p>You may download or make a copy online by selecting <code>File, Download</code> or <code>File, Make a copy</code>.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/03/image-22.png" alt="Image" width="600" height="400" loading="lazy">
<em>Download or make a copy of Google Sheet</em></p>
<p>I'll discuss the Excel version from here on, making reference when something differs in Google Sheets.</p>
<h2 id="heading-video-walkthrough">Video Walkthrough</h2>
<p>Oh, and here's an enjoyable video walkthrough should you feel so inclined. 😁😁</p>
<div class="embed-wrapper">
        <iframe width="560" height="315" src="https://www.youtube.com/embed/vMyBjyHGQ-U" style="aspect-ratio: 16 / 9; width: 100%; height: auto;" title="YouTube video player" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen="" loading="lazy"></iframe></div>
<h2 id="heading-setup">Setup</h2>
<p>I've created a three column order form where a store may inventory their product and enter an amount to order. The third column is used by the warehouse to enter how many were actually delivered. This is a real world setup that we'll use in simplified form for this tutorial.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/03/image-23.png" alt="Image" width="600" height="400" loading="lazy">
<em>Sample order form in Excel</em></p>
<p>It can be difficult for fulfillment if there are zeros entered into the order column. Instead of allowing this, we'll use a couple tools to show how to control values in a cell. No matter how clear the directions are, someone will always forget and enter a zero.</p>
<h2 id="heading-conditional-formatting">Conditional Formatting</h2>
<p>By applying conditional formatting, we can effectively white-out the cells that contain zeros (or any negative values).</p>
<p>From the Home Ribbon in Excel and the Format menu in Google Sheets, select <code>Conditional Formatting</code>. </p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/03/conditional-on-classic-ribbon.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>If you don't see the conditional formatting as an option, it'll be over in the styles dropdown or in the far right in a three-dotted dropdown, depending on whether you've got the classic or the new style of ribbon displayed.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/03/differnt-ribbon.png" alt="Image" width="600" height="400" loading="lazy">
<em>Conditional formatting menu in Excel Ribbons</em></p>
<p>If you want to change your ribbon's layout, select this dropdown arrow at the far right of the ribbon:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/03/ribbon.png" alt="Image" width="600" height="400" loading="lazy">
<em>Change Excel Ribbon layout</em></p>
<p>Once you're in the conditional format menu, click <code>Manage Rules</code>. This will let you specify the formatting depending on a ton of options. </p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/03/manage-rules.png" alt="Image" width="600" height="400" loading="lazy">
<em>Manage conditional formatting rules in Excel</em></p>
<p>This is where Microsoft Excel does have a leg up on Google Sheets. Excel has more options laid out in a more intuitive way. You can do the same things in each program, but Excel has organized theirs a little better in my opinion.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/03/image-26.png" alt="Image" width="600" height="400" loading="lazy">
<em>Conditional formatting menu organization in Excel</em></p>
<p>We are going to select the Order column as our range and then highlight cells with cell values of less than or equals to zero. </p>
<p>At other times, you'll be using conditional formatting to make data visualization using colors and color scales, but in our case, we want to blot out the zero value. </p>
<p>To do this, I've simply selected a white fill color and a white text color. 🤔</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/03/image-25.png" alt="Image" width="600" height="400" loading="lazy">
<em>Conditional formatting menu</em></p>
<p>And now, voilà! If a zero amount is entered, it will simply white out to not distract from the fulfillment center:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/03/zero.png" alt="Image" width="600" height="400" loading="lazy">
<em>Zero value entered and conditional formatting applied</em></p>
<h2 id="heading-data-validation">Data Validation</h2>
<p>The second option at our disposal is data validation. You can find this on the data tab in the ribbon, and if you're not seeing it, you can find it by exploring the same ribbon options I detailed above.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/03/validation-1.png" alt="Image" width="600" height="400" loading="lazy">
<em>Data validation menu in ribbon</em></p>
<p>This will give us a host of options to select to validate the data going into a specified range. There are many options to choose from for our data.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/03/image-30.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>In our case, we want to make sure they are whole numbers greater than zero. Sort of the opposite of the conditional formatting we did above.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/03/image-29.png" alt="Image" width="600" height="400" loading="lazy">
<em>Data validation</em></p>
<p>Another nice Excel feature that's missing at the time of this writing in Google Sheets is the ability to put an Input Message into the data validation.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/03/image-31.png" alt="Image" width="600" height="400" loading="lazy">
<em>Input message in data validation</em></p>
<p>Now, whenever you are on cell in the data validation range, a friendly box will pop up with directions reminding you to not order a zero amount. 😀</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/03/image-32.png" alt="Image" width="600" height="400" loading="lazy">
<em>Example of input text in spreadsheet</em></p>
<p>Data validation in Excel defaults to blocking any input that doesn't adhere to the defined conditions. </p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/03/image-33.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>So, you'll receive an ugly pop up preventing you from entering a zero.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/03/image-34.png" alt="Image" width="600" height="400" loading="lazy">
<em>data validation warning</em></p>
<p>We can improve upon this by setting a custom message here too, though. And we can select whether to block it outright or to allow a zero to be entered after the warning pops up. Effectively allowing the warning to be ignored in the event that there's a reason to do this.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/03/image-35.png" alt="Image" width="600" height="400" loading="lazy">
<em>data validation custom warning message</em></p>
<p>And finally, we can couple any of these options with our conditional formatting so that if we do only warn against the entry, we still blot it out with the white text and white fill color.</p>
<p>The accompanying <a target="_blank" href="https://onedrive.live.com/edit.aspx?resid=FE6EDAF51E9AF322!1141&amp;ithint=file%2cxlsx&amp;authkey=!ANRcKMn_p25YVyo">Excel Sheet</a> and <a target="_blank" href="https://docs.google.com/spreadsheets/d/1gnacOaU_TCX_I7wGxHWWriyej4kI7t9AzM_nLybv9Cs/edit#gid=1341856047">Google Sheet</a> contain four columns of each of the above examples for you to see in action.</p>
<p>I hope this has been helpful for you! </p>
<p>Please come see my <a target="_blank" href="https://www.youtube.com/@eamonncottrell?sub_confirmation=1">video tutorials on YouTube</a>. I'd appreciate a like and subscribe as I'm growing my tech education channel there!</p>
<p>Have a great one!</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ ValueError: math domain error [Solved Python Error] ]]>
                </title>
                <description>
                    <![CDATA[ In mathematics, there are certain operations that are considered to be mathematically undefined operations.  Some examples of these undefined operations are: The square root of a negative number (√-2).  A divisor with a value of zero (20/0).  The "... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/valueerror-python-math-domain-error-solved/</link>
                <guid isPermaLink="false">66b0a3786428eb897141f896</guid>
                
                    <category>
                        <![CDATA[ error ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Python ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Ihechikara Abba ]]>
                </dc:creator>
                <pubDate>Wed, 22 Feb 2023 16:11:13 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2023/02/python-math-domain-error.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>In mathematics, there are certain operations that are considered to be mathematically undefined operations. </p>
<p>Some examples of these undefined operations are:</p>
<ul>
<li>The square root of a negative number (√-2). </li>
<li>A divisor with a value of zero (20/0). </li>
</ul>
<p>The "ValueError: math domain error" error in Python occurs when you carry out a math operation that falls outside the domain of the operation.</p>
<p>To put it simply, this error occurs in Python when you perform a math operation with mathematically undefined values. </p>
<p>In this article, you'll learn how to fix the "ValueError: math domain error" error in Python. </p>
<p>You'll start by learning what the keywords found in the error message mean. You'll then see some practical code examples that raise the error and a fix for each example. </p>
<p>Let's get started!</p>
<h2 id="heading-how-to-fix-the-valueerror-math-domain-error-error-in-python">How to Fix the "ValueError: math domain error" Error in Python</h2>
<p>A <code>valueError</code> is raised when a function or operation receives a parameter with an invalid value. </p>
<p>A domain in math is the range of all possible values a function can accept. All values that fall outside the domain are considered "undefined" by the function. </p>
<p>So the <code>math domain error</code> message simply means that you're using a value that falls outside the accepted domain of a function.</p>
<p>Here are some examples:</p>
<h3 id="heading-example-1-python-math-domain-error-with-mathsqrt">Example #1 – Python Math Domain Error With <code>math.sqrt</code></h3>
<pre><code class="lang-python"><span class="hljs-keyword">import</span> math

print(math.sqrt(<span class="hljs-number">-1</span>))
<span class="hljs-comment"># ValueError: math domain error</span>
</code></pre>
<p>In the code above, we're making use of the <code>sqrt</code> method from the <code>math</code> module to get the square root of a number. </p>
<p>We're getting the "ValueError: math domain error" returned because -1 falls outside the range of numbers whose square root can be obtained mathematically. </p>
<h3 id="heading-solution-1-python-math-domain-error-with-mathsqrt">Solution #1 – Python Math Domain Error With <code>math.sqrt</code></h3>
<p>To fix this error, simply use an <code>if</code> statement to check if the number is negative before proceeding to find the square root. </p>
<p>If the number is greater than or equal to zero, then the code can be executed. Otherwise, a message would be printed out to notify the user that a negative number can't be used. </p>
<p>Here's a code example:</p>
<pre><code class="lang-python"><span class="hljs-keyword">import</span> math

number = float(input(<span class="hljs-string">'Enter number: '</span>))

<span class="hljs-keyword">if</span> number &gt;= <span class="hljs-number">0</span>:
    print(<span class="hljs-string">f'The square root of <span class="hljs-subst">{number}</span> is <span class="hljs-subst">{math.sqrt(number)}</span>'</span>)
<span class="hljs-keyword">else</span>: 
    print(<span class="hljs-string">'Cannot find the square root of a negative number'</span>)
</code></pre>
<h3 id="heading-example-2-python-math-domain-error-with-mathlog">Example #2 – Python Math Domain Error With <code>math.log</code></h3>
<p>You use the <code>math.log</code> method to get the logarithm of a number. Just like the <code>sqrt</code> method, you can't get the log of a negative number. </p>
<p>Also, you can't get the log of the number 0. So we have to modify the condition of the <code>if</code> statement to check for that. </p>
<p>Here's an example that raises the error:</p>
<pre><code class="lang-python"><span class="hljs-keyword">import</span> math

print(math.log(<span class="hljs-number">0</span>))
<span class="hljs-comment"># ValueError: math domain error</span>
</code></pre>
<h3 id="heading-solution-2-python-math-domain-error-with-mathlog">Solution #2 – Python Math Domain Error With <code>math.log</code></h3>
<pre><code class="lang-python"><span class="hljs-keyword">import</span> math

number = float(input(<span class="hljs-string">'Enter number: '</span>))

<span class="hljs-keyword">if</span> number &gt; <span class="hljs-number">0</span>:
    print(<span class="hljs-string">f'The log of <span class="hljs-subst">{number}</span> is <span class="hljs-subst">{math.log(number)}</span>'</span>)
<span class="hljs-keyword">else</span>: 
    print(<span class="hljs-string">'Cannot find the log of 0 or a negative number'</span>)
</code></pre>
<p>In the code above, we're using the condition of the <code>if</code> statement to make sure the number inputted by the user is neither zero nor a negative number (the number must be greater than zero).</p>
<h3 id="heading-example-3-python-math-domain-error-with-mathacos">Example #3 – Python Math Domain Error With <code>math.acos</code></h3>
<p>You use the <code>math.acos</code> method to find the arc cosine value of a number. </p>
<p>The domain of the <code>acos</code> method is from -1 to 1, so any value that falls outside that range will raise the "ValueError: math domain error" error. </p>
<p>Here's an example:</p>
<pre><code class="lang-python"><span class="hljs-keyword">import</span> math

print(math.acos(<span class="hljs-number">2</span>))
<span class="hljs-comment"># ValueError: math domain error</span>
</code></pre>
<h3 id="heading-solution-3-python-math-domain-error-with-mathacos">Solution #3 – Python Math Domain Error With <code>math.acos</code></h3>
<pre><code class="lang-python"><span class="hljs-keyword">import</span> math

number = float(input(<span class="hljs-string">'Enter number: '</span>))

<span class="hljs-keyword">if</span> <span class="hljs-number">-1</span> &lt;= number &lt;= <span class="hljs-number">1</span>:
    print(<span class="hljs-string">f'The arc cosine of <span class="hljs-subst">{number}</span> is <span class="hljs-subst">{math.acos(number)}</span>'</span>)
<span class="hljs-keyword">else</span>:
    print(<span class="hljs-string">'Please enter a number between -1 and 1.'</span>)
</code></pre>
<p>Just like the solution in other examples, we're using an <code>if</code> statement to make sure the number inputted by the user doesn't exceed a certain range. </p>
<p>That is, any value that falls outside the range of -1 to 1 will prompt the user to input a correct value. </p>
<h2 id="heading-summary">Summary</h2>
<p>In this article, we talked about the "ValueError: math domain error" error in Python. </p>
<p>We had a look at some code examples that raised the error, and how to check for and fix them using an <code>if</code> statement. </p>
<p>Happy coding!</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ Type Error vs Reference Error in JavaScript – What's the Difference? ]]>
                </title>
                <description>
                    <![CDATA[ As a JavaScript developer, you've likely encountered different types of errors while coding. Most of the time these will be type errors or reference errors. But have you ever wondered what they mean? Have you ever tried reading about the error type s... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/type-error-vs-reference-error-javascript/</link>
                <guid isPermaLink="false">66ba2a4b4ae6042994edfa2e</guid>
                
                    <category>
                        <![CDATA[ error ]]>
                    </category>
                
                    <category>
                        <![CDATA[ error handling ]]>
                    </category>
                
                    <category>
                        <![CDATA[ JavaScript ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Tejan Singh ]]>
                </dc:creator>
                <pubDate>Wed, 15 Feb 2023 17:12:30 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2023/02/pexels-kim-stiver-909256.jpg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>As a JavaScript developer, you've likely encountered different types of errors while coding. Most of the time these will be type errors or reference errors. But have you ever wondered what they mean?</p>
<p>Have you ever tried reading about the error type specified by the interpreter before solving these errors? If not, you should, since knowing about these errors can help you solve your problems.</p>
<p>For example, when you encounter an error, you probably Google it. You copy and paste the whole error and try to find out the solution, by visiting various websites and forums. It's a trial and error method of finding and solving bugs.</p>
<p>But what if you already knew why the error generally occurs? This would save you time you'd otherwise spend searching for solutions online. Instead, you could start looking for solutions on your own just by looking at the error type.</p>
<p>In this guide, you will learn about the two mostly encountered error types, which are type error and reference error. You'll learn why they occur, the difference between them, and how to avoid getting these errors.</p>
<p>Note: There are other types of errors in JavaScript like syntax errors, internal errors, range errors, and eval errors. But the scope of this article is limited to the two most commonly occurring errors.</p>
<h2 id="heading-what-is-a-type-error">What is a Type Error?</h2>
<p>Type errors occur when you use something that is not intended to be used in that particular way. For example, using a screwdriver to hammer in a nail, instead of using a hammer.</p>
<p>Let's understand this using an example:</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">let</span> a = <span class="hljs-number">1</span>
<span class="hljs-built_in">console</span>.log(a()) 

<span class="hljs-comment">//output</span>
Uncaught <span class="hljs-built_in">TypeError</span>: a is not a <span class="hljs-function"><span class="hljs-keyword">function</span></span>
</code></pre>
<p>Here <code>a</code> is a variable initialized with a value. You encountered an error because you tried to call a function with the variable name. A variable cannot be called as a function. Functions and variables work differently. So in this case, you got a type error. You used the <code>let</code> variable differently from its <em>type.</em> </p>
<p>This gives us a type error.</p>
<p>Solution: To resolve this error, you must refer to the variable in the console, as it is intended to be used. In this case, you pass <code>a</code> as a variable instead of a function.</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">let</span> a = <span class="hljs-number">1</span>
<span class="hljs-built_in">console</span>.log(a)

<span class="hljs-comment">//output</span>
<span class="hljs-number">1</span>
</code></pre>
<p>Let's take another example:</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> a = <span class="hljs-number">1</span>
a = <span class="hljs-number">2</span> <span class="hljs-comment">// you reassign a const type variable again</span>

<span class="hljs-comment">//output</span>
<span class="hljs-attr">TypeError</span>: Assignment to constant variable.
</code></pre>
<p>Here, we reassigned the <code>const</code> type variable <code>a</code> to a new value. But you can't change const variables like this, so in this case you get a type error</p>
<p>Solution: never reassign a <code>const</code> type variable once you've defined it.</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> a = <span class="hljs-number">1</span>
<span class="hljs-keyword">const</span> b = <span class="hljs-number">2</span>
<span class="hljs-built_in">console</span>.log(a, b)

<span class="hljs-comment">//output</span>
<span class="hljs-number">1</span> <span class="hljs-number">2</span>
</code></pre>
<p>Here's another example using an array:</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> myArray = [<span class="hljs-number">1</span>,<span class="hljs-number">2</span>,<span class="hljs-number">3</span>,<span class="hljs-number">4</span>]
myArray = myArray.push(<span class="hljs-number">5</span>) <span class="hljs-comment">// reassign array</span>

<span class="hljs-comment">//output</span>
<span class="hljs-attr">TypeError</span>: Assignment to constant variable.
</code></pre>
<p>In this case, we reassigned the <code>const</code> type <code>myArray</code>. This gives us a type error because again, this kind of reassignment is against the properties of <code>const</code>. </p>
<p>Solution:</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> myArray = [<span class="hljs-number">1</span>,<span class="hljs-number">2</span>,<span class="hljs-number">3</span>,<span class="hljs-number">4</span>]
myArray.push(<span class="hljs-number">5</span>) <span class="hljs-comment">// you can push new values</span>

<span class="hljs-comment">//output</span>
[<span class="hljs-number">1</span>,<span class="hljs-number">2</span>,<span class="hljs-number">3</span>,<span class="hljs-number">4</span>,<span class="hljs-number">5</span>]
</code></pre>
<p>You can easily push new values to the array without reassigning it. This will not give you any error. Pushing values into an array is allowed. This way you can avoid getting the error.</p>
<h3 id="heading-how-to-avoid-getting-a-type-error">How to avoid getting a type error</h3>
<p>The easiest way to prevent type errors is to avoid using the same names for different variables and functions. </p>
<p>If you use different names, you will not get confused or replace one with another, and you can easily avoid getting this error.</p>
<p>Another way is to make sure you use variables as they're intended to be used. Instead of using <code>const</code> when you need to reassign a value, use <code>let</code> (which allows this kind of change).</p>
<h2 id="heading-what-is-a-reference-error">What is a Reference Error?</h2>
<p>Reference errors occur when you are trying to refer to or use something that does not exist. For example, looking for a screwdriver in your toolbox, but it's not there.</p>
<p>Let's understand this using an example:</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">let</span> a = <span class="hljs-number">1</span>
<span class="hljs-built_in">console</span>.log(b) <span class="hljs-comment">// undefined variable used</span>

<span class="hljs-comment">//output</span>
Uncaught <span class="hljs-built_in">ReferenceError</span>: b is not defined
</code></pre>
<p>Here, <code>a</code> is a variable initialized with a value. We encountered an error because we tried to console log the variable <code>b</code> that does not exist. We hadn't yet declared any such variable, so we got a reference error here.</p>
<p>Solution: only use a variable that you've declared to avoid getting an error.</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">let</span> a = <span class="hljs-number">1</span>
<span class="hljs-built_in">console</span>.log(a) <span class="hljs-comment">// used defined variable</span>

<span class="hljs-comment">//output</span>
<span class="hljs-number">1</span>
</code></pre>
<p>Here's another example:</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">if</span>(<span class="hljs-literal">true</span>){
    <span class="hljs-keyword">let</span> a = <span class="hljs-number">1</span>
}

<span class="hljs-built_in">console</span>.log(a)

<span class="hljs-comment">//output</span>
<span class="hljs-attr">ReferenceError</span>: a is not defined
</code></pre>
<p>In this example, we're trying to access the <code>a</code> variable of type <code>let</code> outside its block. The interpreter cannot find it outside the block. This gives us an error.</p>
<p>Solution:</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">if</span>(<span class="hljs-literal">true</span>){
    <span class="hljs-keyword">let</span> a = <span class="hljs-number">1</span>
    <span class="hljs-built_in">console</span>.log(a)
}


<span class="hljs-comment">//output</span>
<span class="hljs-number">1</span>
</code></pre>
<p>Using the variable inside its block or scope will not give you any error.</p>
<p>Let's take one more example, but this one can be difficult to understand.</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">if</span>(<span class="hljs-literal">true</span>){
    <span class="hljs-built_in">console</span>.log(a)
    <span class="hljs-keyword">let</span> a = <span class="hljs-number">1</span>
}


<span class="hljs-comment">//output</span>
<span class="hljs-attr">ReferenceError</span>: Cannot access <span class="hljs-string">'a'</span> before initialization
</code></pre>
<p><code>a</code> is still inside its scope. But we get an error. Why? Because we're trying to use the variable before we've defined it. This is not allowed and goes against the properties of the <code>let</code> variable. </p>
<p>Solution: use the <code>let</code> variable only after defining it. </p>
<pre><code class="lang-javascript"><span class="hljs-keyword">if</span>(<span class="hljs-literal">true</span>){
    <span class="hljs-keyword">let</span> a = <span class="hljs-number">1</span>
    <span class="hljs-built_in">console</span>.log(a)

}

<span class="hljs-comment">//output</span>
<span class="hljs-number">1</span>
</code></pre>
<h3 id="heading-how-to-avoid-getting-a-reference-error">How to avoid getting a reference error</h3>
<p>The easiest way to avoid getting reference errors is to refer to or access only defined variables. Only use variables that exist. </p>
<p>You can also use conditional statements and error handling to avoid running code if a variable or a function does not exist.</p>
<h2 id="heading-conclusion">Conclusion</h2>
<p>You can easily debug your code when you already know how to resolve your errors. It's good to know commonly occurring errors and how to avoid them. This will save you time searching for solutions online and wasting hours trying to find a solution when a little bit of knowledge and awareness about these things can help.</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ How to Handle Errors in Computer Networks ]]>
                </title>
                <description>
                    <![CDATA[ There are some magical things about the Internet, and one thing in particular is that it works. In spite of so many obstacles, we can deliver our packets over the globe, and do so fast. Even more specifically, one amazing thing about the Internet is ... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/how-to-handle-errors-in-computer-networks/</link>
                <guid isPermaLink="false">66c17c3858ee0865d2671b5d</guid>
                
                    <category>
                        <![CDATA[ computer network ]]>
                    </category>
                
                    <category>
                        <![CDATA[ computer networking ]]>
                    </category>
                
                    <category>
                        <![CDATA[ error ]]>
                    </category>
                
                    <category>
                        <![CDATA[ error handling ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Omer Rosenbaum ]]>
                </dc:creator>
                <pubDate>Wed, 18 Jan 2023 16:05:43 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2023/01/Copy-of-Computer-Networks-Hub-Switch.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>There are some magical things about the Internet, and one thing in particular is that it works. In spite of so many obstacles, we can deliver our packets over the globe, and do so fast.</p>
<p>Even more specifically, one amazing thing about the Internet is its ability to handle errors. </p>
<p>What do I mean by errors? When a packet or a frame is received by a machine, we say it contains an error if the data that had been sent is not the data that was received. For instance, a single <code>1</code> was mistakenly received as a <code>0</code> after its transmission. </p>
<p>This can happen due to many different reasons. Perhaps there was some disturbance in the wire where the data was transmitted – say, a child rode her bicycle over the wire. Perhaps there was some collision in the air as many people transmitted at once. Maybe it was a device's error.</p>
<p>Regardless of the specific reason, you still get valid data on the Internet. Without handling errors, you may read the last sentence and instead of <code>errors</code> read <code>errbbb</code>. Weird, isn't it? So how does the Internet handle errors?</p>
<p>There are two main approaches for handling errors – detection, and correction. We shall start by describing detection, and then talk about correction.</p>
<h1 id="heading-what-is-error-detection">What is Error Detection?</h1>
<p>When dealing with error detection, we are looking for a boolean result – <code>True</code>, or <code>False</code>. Is the frame/packet valid, or not. That is all. We don’t want to know where the error occurred. If the frame is invalid, we will simply drop it.</p>
<p>So when the receiver receives a frame, they will determine whether an error has occurred. If the frame is valid, they will read it. If the frame contains errors - the receiver will drop it.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/01/image-84.png" alt="Image" width="600" height="400" loading="lazy">
_Error Detection: we only want to know if the frame/packet is valid or not. (<a target="_blank" href="https://www.youtube.com/watch?v=H_bYtVDF6T4&amp;ab_channel=Brief">Source: Brief</a>)_</p>
<p>One method for error detection is using a <strong>checksum</strong>. A common implementation of a checksum is called <strong>CRC – Cyclic Redundancy Check</strong>. </p>
<p>In this post we will not trouble ourselves with the mathematical implementation of CRCs in the real world (if you're interested, check out <a target="_blank" href="https://en.wikipedia.org/wiki/Cyclic_redundancy_check">Wikipedia</a>). Rather, we'll simply try to understand the concept. To do so, let’s implement a very simple checksum mechanism ourselves.</p>
<p>Consider a protocol for transmitting 10-digit phone numbers between endpoints. This protocol is extremely simple: each packet includes exactly 10 bytes, each one representing a digit. For example, a packet might include the following digits:</p>
<p><code>5551234567</code></p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/01/image-85.png" alt="Image" width="600" height="400" loading="lazy">
_A packet with a payload of 10 digits (<a target="_blank" href="https://www.youtube.com/watch?v=H_bYtVDF6T4&amp;ab_channel=Brief">Source: Brief</a>)_</p>
<p>For simplicity's sake, we will omit the headers of the packet and focus solely on the payload. </p>
<p>Now, we will add a checksum. Say that we <strong>add</strong> all the digits. So in this example, we would calculate <code>5</code> + <code>5</code> +<code>5</code> +<code>1</code>+… all the way through <code>7</code>. We would get <code>43</code>. This would be our checksum value.</p>
<p>Now, the sender won’t only send the phone number, but also the checksum value right after it. In this example, the sender would send:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/01/image-86.png" alt="Image" width="600" height="400" loading="lazy">
_The packet's data is followed by a checksum. (<a target="_blank" href="https://www.youtube.com/watch?v=H_bYtVDF6T4&amp;ab_channel=Brief">Source: Brief</a>)_</p>
<p>Now, as the receiver, you can do the same thing. You will read the phone number, and calculate the checksum. You will add the digits, and get <code>43</code>. </p>
<p>Since you've received the correct result (that is, your calculation based on the data matches the checksum value sent in the packet), you can assume that the frame is valid.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/01/image-89.png" alt="Image" width="600" height="400" loading="lazy">
_The sender compares their calculated checksum value and the checksum in the packet. If the values match, the packet is assumed to be valid (<a target="_blank" href="https://www.youtube.com/watch?v=H_bYtVDF6T4&amp;ab_channel=Brief">Source: Brief</a>)_</p>
<p>What happens in case of an error? 🤔</p>
<p>Let’s say, for instance, that the digit <code>2</code> was replaced by an <code>8</code>. Now, even though the sender sent the same stream as before ( <code>555123456743</code> ), you, as the receiver, see something a bit different:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/01/image-90.png" alt="Image" width="600" height="400" loading="lazy">
_A packet containing an error (<a target="_blank" href="https://www.youtube.com/watch?v=H_bYtVDF6T4&amp;ab_channel=Brief">Source: Brief</a>)_</p>
<p>Now, you are calculating the checksum, adding all the digits. You get <code>49</code>. Since this value is different from the checksum value specified in the original frame, <code>43</code>, the frame is considered to be invalid and you drop it.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/01/image-91.png" alt="Image" width="600" height="400" loading="lazy">
_The sender compares their calculated checksum value and the checksum in the packet. If the values don't match, the packet is assumed to be invalid (<a target="_blank" href="https://www.youtube.com/watch?v=H_bYtVDF6T4&amp;ab_channel=Brief">Source: Brief</a>)_</p>
<p>Are there problems with this method? 🤔</p>
<p>Yes, there are. Consider, for example, what happens if there are two errors – and instead of the original stream ( <code>555123456743</code> ), you receive the following:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/01/image-92.png" alt="Image" width="600" height="400" loading="lazy">
_A packet received with two errors, resulting in the stream <code>456123456743</code> (<a target="_blank" href="https://www.youtube.com/watch?v=H_bYtVDF6T4&amp;ab_channel=Brief">Source: Brief</a>)_</p>
<p>What happens when you add the digits?</p>
<p>Even though the digits are not the same as the original packet, the checksum will remain correct, and the frame will be regarded as valid.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/01/image-93.png" alt="Image" width="600" height="400" loading="lazy">
_Despite the errors, the checksum value happens to be correct, resulting in a false assumption that the packet is valid (<a target="_blank" href="https://www.youtube.com/watch?v=H_bYtVDF6T4&amp;ab_channel=Brief">Source: Brief</a>)_</p>
<p>Real checksum functions, such as CRCs, are of course much better implemented than the one in our example – but in extremely rare cases, such problems may occur. </p>
<p>Notice that using this kind of method, error detection, we don’t know where the problem occurred, but only whether the frame is valid or not. If the checksum value is invalid, we assume that the frame is invalid and drop it.</p>
<h1 id="heading-what-is-error-correction">What is Error Correction?</h1>
<p>As mentioned earlier, detection is not the only way to handle errors. Another approach might be to find the error and correct it. How can we do that?</p>
<p>An extremely simple way would be to transmit the data many times – let’s say, three times. For example, the stream <code>5551234567</code> would be transmitted as follows:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/01/image-94.png" alt="Image" width="600" height="400" loading="lazy">
_Sending the same data multiple times (<a target="_blank" href="https://www.youtube.com/watch?v=H_bYtVDF6T4&amp;ab_channel=Brief">Source: Brief</a>)_</p>
<p>So we basically sent the data three times.</p>
<p>Now, in case of an error in one digit, the receiver can look at the other two digits, and choose the one that appears two times out of three.</p>
<p>So, for instance, if we had a problem and <code>2</code> was replaced with an <code>8</code>, the receiver would get this stream:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/01/image-95.png" alt="Image" width="600" height="400" loading="lazy">
_An error in one of the occurrences of the data (<a target="_blank" href="https://www.youtube.com/watch?v=H_bYtVDF6T4&amp;ab_channel=Brief">Source: Brief</a>)_</p>
<p>Now, as a receiver, you can say: “I have <code>2</code>, <code>8</code>, <code>2</code>… so it was probably <code>2</code> in the original message”.</p>
<p>Is this problematic? Well, in some rare cases, we might get the same error twice. So it is possible, even though unlikely, that two of the original twos have been received as eights.</p>
<p>So while the sender sent this stream:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/01/image-94.png" alt="Image" width="600" height="400" loading="lazy">
_Sending the same data multiple times (<a target="_blank" href="https://www.youtube.com/watch?v=H_bYtVDF6T4&amp;ab_channel=Brief">Source: Brief</a>)_</p>
<p>The first <code>2</code> was mistakenly read as an <code>8</code>, and also the second <code>2</code> was received as an <code>8</code>:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/01/image-96.png" alt="Image" width="600" height="400" loading="lazy">
_Two identical errors; Rare, but possible (<a target="_blank" href="https://www.youtube.com/watch?v=H_bYtVDF6T4&amp;ab_channel=Brief">Source: Brief</a>)_</p>
<p> Now, it looks as if the original message included an <code>8</code>, and not a <code>2</code>.</p>
<p>What can you do in order to lower the probability of such scenario?</p>
<p>The most simple solution would be to simply send the data even more times. Let’s say, five times. So now we duplicate all the data, and send it 5 times in total… </p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/01/image-97.png" alt="Image" width="600" height="400" loading="lazy">
_Sending the data five(!) times (<a target="_blank" href="https://www.youtube.com/watch?v=H_bYtVDF6T4&amp;ab_channel=Brief">Source: Brief</a>)_</p>
<p>Now, say that two errors occurred, and again two of the <code>2</code> digits were replaced with <code>8</code>s.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/01/image-98.png" alt="Image" width="600" height="400" loading="lazy">
_Two identical errors; Rare, but possible (<a target="_blank" href="https://www.youtube.com/watch?v=H_bYtVDF6T4&amp;ab_channel=Brief">Source: Brief</a>)_</p>
<p>Clearly, it is very unlikely to get the same error twice, but even in this case, we still get <code>2</code> three times, so as the receiver you can tell, with a high probability, that the original message contained a <code>2</code>, rather than an <code>8</code>.</p>
<h2 id="heading-whats-the-overhead">What's the Overhead?</h2>
<p>Now would be a good time to introduce the term <strong>overhead</strong>. When we say overhead, we basically mean data or time needed to convey the actual message. Let’s first understand what this term means in general, and then consider it in the context of handling errors.</p>
<p>Let’s say that I have a lesson to teach in my university. My goal is to teach the lesson itself, which is also called the <strong>payload</strong> in that context – that is, the actual data or message I would like to convey.</p>
<p>In order to teach the lesson, or to convey the payload, I first have to physically get to the university – so I get out of my home, walk to the bus station, wait for the bus, take the bus, get off the bus, walk to the building, wait for the lesson to start – and only then do I actually get to teach the lesson. </p>
<p>This entire process is <strong>overhead</strong> that I have to pay in order to deliver the <strong>payload</strong>, in this case – to teach the lesson.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/01/image-99.png" alt="Image" width="600" height="400" loading="lazy">
_Overhead and Payload are two extremely important terms in Computer Networks (<a target="_blank" href="https://www.youtube.com/watch?v=H_bYtVDF6T4&amp;ab_channel=Brief">Source: Brief</a>)_</p>
<p>The same applies in computer networks. Our <strong>payload</strong> is the data, and there is always some <strong>overhead</strong> associated with sending it. </p>
<h2 id="heading-back-to-handling-errors">Back to Handling Errors</h2>
<p>In the context here – sending the data three times, as suggested earlier, means that for every byte of payload we have two bytes of overhead. If we send the data five times, then for every byte of payload, we have four bytes of overhead. That’s a LOT!</p>
<p>Consider error <em>detection</em>, on the other hand. In our example protocol for sending phone numbers, how much overhead did we have?</p>
<p>Recall that for every ten-digit phone number, that is ten bytes, we included a two-digit checksum value. In other words, we had two bytes of overhead for ten bytes of payload. It is clear that in our example, error detection yields much smaller overhead in comparison to error correction.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/01/image-100.png" alt="Image" width="600" height="400" loading="lazy">
_In the sample protocol, for every ten-digit phone number (ten bytes of payload), we included a two-digit checksum value (two bytes of overhead) (<a target="_blank" href="https://www.youtube.com/watch?v=H_bYtVDF6T4&amp;ab_channel=Brief">Source: Brief</a>)_</p>
<p>There are better ways to achieve error correction with high accuracy than to simply send the data so many times, but they are more complicated and out of scope for this post. Even with very complicated error correction techniques, they still require lots of overhead when compared to error detection.</p>
<p>Also, notice that except for the bytes sent as overhead in case of error correction, error detection is much simpler. </p>
<h1 id="heading-error-correction-vs-error-detection-which-is-better">Error Correction vs Error Detection – Which is Better?</h1>
<p>We already concluded that error detection is simpler, and with a smaller payload compared to error correction.</p>
<h3 id="heading-so-when-would-we-prefer-error-correction">So, when would we prefer error correction?</h3>
<p>One case might be when we have a one-way link. That is, a network where we can only transfer data in one direction. </p>
<p>For example, say you have a secret agent that you need to send a message to. The agent knows that they need to look up to the sky at exactly midnight, and they will see a series of flashes indicating the secret message. </p>
<p>The secret agent cannot reply, or their location and identity will be revealed. In addition, you don’t want to send the message over and over again, as not to draw much attention, and to make it harder for someone to intercept the message.</p>
<p>In this case, you definitely want your agent to receive the exact message that you’ve sent. Consider a case where you want to send them the message “do not place the bomb”. </p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/01/image-101.png" alt="Image" width="600" height="400" loading="lazy">
_A sensitive message for a secret agent (<a target="_blank" href="https://www.youtube.com/watch?v=H_bYtVDF6T4&amp;ab_channel=Brief">Source: Brief</a>)_</p>
<p>Of course, you don’t want to risk the unfortunate scenario of the agent reading the message as “do <strong>now</strong> place the bomb”, due to an error.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/01/image-102.png" alt="Image" width="600" height="400" loading="lazy">
_An error may change the meaning of the message substantially (<a target="_blank" href="https://www.youtube.com/watch?v=H_bYtVDF6T4&amp;ab_channel=Brief">Source: Brief</a>)_</p>
<p>If you use error <em>detection</em>, the agent might be aware that the message they received is invalid in case of an error, but they won’t be able to tell you that they need you to send the message again. As you want the agent to be able to read your message correctly and without sending any data back to us, error correction is preferred.</p>
<p>So, one-way link is one case where we prefer error correction. What about other cases?</p>
<p>Sometimes you just <em>can’t</em> send the data again, perhaps because it has been erased from the memory of your machine. That is, the data is deleted right after it has been sent. In this case, you'd clearly prefer error correction, as sending the data again, as we would do with error detection, is just impossible.</p>
<p>Also, if sending the data again is possible, but extremely expensive, error correction may be preferable. </p>
<p>For example, if you send a message to the moon, say, with a spaceship – it might be really expensive to send it over again in case of an error. Using error correction, you send the data only once and the receiver should be able to deal with it, even if an error occurred.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/01/image-103.png" alt="Image" width="600" height="400" loading="lazy">
_Cases where correction is preferred (<a target="_blank" href="https://www.youtube.com/watch?v=H_bYtVDF6T4&amp;ab_channel=Brief">Source: Brief</a>)_</p>
<p>In general, we prefer error correction when retransmitting the data is costly or impossible. </p>
<h3 id="heading-when-would-we-prefer-error-detection">When would we prefer error detection?</h3>
<p>Well, in case we can retransmit the data, we usually prefer error detection since it comes with very little overhead compared to error correction. Especially, when sending the data is relatively cheap.</p>
<p>For example, on the Internet, if an error occurs when you send a frame, no problem – you can simply send it again! </p>
<p>For example, when I covered <a target="_blank" href="https://www.freecodecamp.org/news/the-complete-guide-to-the-ethernet-protocol/">the Ethernet protocol in a previous post</a>, I mentioned that Ethernet protocol uses change detection, namely <code>CRC32</code> – that is, 32 bits (or 4 bytes) of a checksum for every frame. </p>
<p>Note that it doesn’t mean that error detection is simply better. It just better fits the Internet than error correction. As mentioned before, error correction is preferable in other cases.</p>
<h1 id="heading-wrapping-up">Wrapping Up</h1>
<p>In this tutorial, we discussed various methods for handling errors. We looked at <strong>error detection</strong>, where we only know whether a frame is valid or not. We also considered <strong>error correction</strong>, where the receiver can restore the correct value of an erroneous frame. We also introduced the term <strong>overhead</strong>. </p>
<p>We then understood why we use error detection on the Internet, rather than error correction. Stay tuned for more posts in this series about Computer Networks 💪🏻</p>
<h2 id="heading-about-the-author"><strong>About the Author</strong></h2>
<p><a target="_blank" href="https://www.linkedin.com/in/omer-rosenbaum-034a08b9/">Omer Rosenbaum</a> is <a target="_blank" href="https://swimm.io/">Swimm</a>’s Chief Technology Officer. He's the author of the Brief <a target="_blank" href="https://youtube.com/@BriefVid">YouTube Channel</a>. He's also a cyber training expert and founder of Checkpoint Security Academy. He's the author of <a target="_blank" href="https://data.cyber.org.il/networks/networks.pdf">Computer Networks (in Hebrew)</a>. You can find him on <a target="_blank" href="https://twitter.com/Omer_Ros">Twitter</a>.</p>
<h2 id="heading-additional-resources"><strong>Additional Resources</strong></h2>
<ul>
<li><a target="_blank" href="https://www.youtube.com/playlist?list=PL9lx0DXCC4BMS7dB7vsrKI5wzFyVIk2Kg">Computer Networks Playlist - on my Brief channel</a></li>
<li><a target="_blank" href="https://en.wikipedia.org/wiki/Cyclic_redundancy_check">CRC - Wikipedia</a></li>
<li><a target="_blank" href="https://www.freecodecamp.org/news/the-complete-guide-to-the-ethernet-protocol/">The Complete Guide to Ethernet Protocol</a></li>
</ul>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ Laravel Valet Performance – How to Prevent 504 Errors and Speed Up Valet ]]>
                </title>
                <description>
                    <![CDATA[ Last week, I decided to install Laravel Valet on my Mac. But after the installation, the performance of the microservice architecture application I had it on was quite slow.  I wondered if it was an M1 issue or because I had yet to shut the machine d... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/speed-up-performance-in-laravel-valet/</link>
                <guid isPermaLink="false">66ba2fcfde9370f66eeb0a9d</guid>
                
                    <category>
                        <![CDATA[ error ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Laravel ]]>
                    </category>
                
                    <category>
                        <![CDATA[ PHP ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Sule-Balogun Olanrewaju ]]>
                </dc:creator>
                <pubDate>Mon, 02 Jan 2023 23:12:30 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2023/01/pexels-jonathan-petersson-399636.jpg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>Last week, I decided to install Laravel Valet on my Mac. But after the installation, the performance of the microservice architecture application I had it on was quite slow. </p>
<p>I wondered if it was an M1 issue or because I had yet to shut the machine down. I shut down, and the problem persisted. And I couldn't find anything online indicating that it was an issue with M1. So how could I fix it?</p>
<p><strong>In this tutorial, you'll learn:</strong></p>
<ul>
<li>Why does the Error 504 occur?</li>
<li>What is Laravel Valet and how does it work?</li>
<li>Valet commands you should know</li>
<li>How to fix the 504 error and speed up performance in Valet</li>
</ul>
<h2 id="heading-why-does-the-error-504-occur">Why does the Error 504 occur?</h2>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/12/image-145.png" alt="Image" width="600" height="400" loading="lazy">
<em>Error 504 Nginx</em></p>
<p>Error 504, also known as "Gateway timeout", is an error that occurs when a server takes longer than usual to respond to an HTTP request. This makes it unable to complete the request cycle. </p>
<p>The Gateway timeout is a server-side error caused by several things. It can result from network connectivity issues when the server exceeds the default limit of <strong>256M</strong> or an execution time of <strong>60 seconds</strong>, an overloaded server, firewall, and so on. </p>
<p>This error happens with local servers, too, such as XAMPP, WAMP and Valet, during the local development lifecycle. </p>
<p>This article will help you fix this problem on Valet by adding some configurations to speed up the server request lifecycle.</p>
<h2 id="heading-what-is-laravel-valet-and-how-does-it-work">What is Laravel Valet and How Does It Work?</h2>
<p>Laravel Valet is a development environment for macOS, Windows, and other operating systems. Once installed, Valet runs Nginx processes in the background when your laptop comes on.</p>
<p>Unlike other development environments like XAMPP and WAMP, you'll have to manually start your server each time you set out to work. Valet then uses DnsMasq to proxy all parked applications to a <code>.test</code> domain. </p>
<p>So, for instance, you would access on XAMPP server <code>http://localhost/application</code> but on valet, you would do <code>http://application.test</code>, and it will point to where the application is installed. </p>
<p>Working with Valet means you don't have to put all applications in an htdocs or www directory. Instead, any random directory you create will work just perfectly in Valet. </p>
<h2 id="heading-helpful-valet-commands-you-should-know">Helpful Valet Commands You Should Know:</h2>
<ul>
<li><strong><code>valet park</code>:</strong> Registers all applications/sites in a directory and exposes them with the .test domain.</li>
</ul>
<pre><code>cd ~/project_directory
valet park
</code></pre><ul>
<li><strong><code>valet parked</code>:</strong> Gives a tabular breakdown of all registered sites. Information like site name, SSL, URL, and path is available.</li>
</ul>
<pre><code>cd ~/project_directory
valet parked
</code></pre><ul>
<li><strong><code>valet secure</code>:</strong> Secures your application with an SSL certificate and makes the site accessible over HTTPS.</li>
</ul>
<pre><code>cd ~<span class="hljs-regexp">/project_directory/</span>site
valet secure
</code></pre><ul>
<li><strong><code>valet unsecure</code>:</strong> Use this command to unsecure your site and revert to serving over HTTP.</li>
</ul>
<pre><code>cd ~<span class="hljs-regexp">/project_directory/</span>site
valet unsecure
</code></pre><ul>
<li><strong><code>valet isolate</code>:</strong> Isolates a particular site and makes it run on a different PHP version that's not the globally installed version. You can run <code>php -v</code> on the terminal to see the version. But if some of your applications want to downgrade or upgrade, you should use the isolate command and specify the version you need. The isolate command below, enforce the site to use PHP version 7.4:</li>
</ul>
<pre><code>cd ~<span class="hljs-regexp">/project_directory/</span>site
valet isolate @php7<span class="hljs-number">.4</span>
</code></pre><ul>
<li><strong><code>valet unisolate</code>:</strong> Reverts a site back to the globally installed PHP version.</li>
</ul>
<pre><code>cd ~<span class="hljs-regexp">/project_directory/</span>site
valet unisolate
</code></pre><ul>
<li><strong><code>valet restart</code>:</strong> The restart command ensures all valet services are restarted. It's useful when configurations are modified, updated, and installed.</li>
</ul>
<pre><code>cd ~<span class="hljs-regexp">/project_directory/</span>site
valet restart
</code></pre><ul>
<li><strong><code>valet -v</code>:</strong> This command helps check the the current Valet version. Not only that, but the command also shows a list of all available commands and descriptions of what they do in Valet.</li>
</ul>
<pre><code>~<span class="hljs-regexp">/project_directory/</span>site
valet -v
</code></pre><p><img src="https://www.freecodecamp.org/news/content/images/2022/12/Screenshot-2022-12-26-at-11.33.10.png" alt="Image" width="600" height="400" loading="lazy">
<em>Valet available commands</em></p>
<h2 id="heading-how-to-speed-up-performance-in-valet">How to Speed Up Performance in Valet</h2>
<p>Over in the terminal, we will need to create a file <code>www.conf</code> in a directory and then add the configuration settings we need.</p>
<p>Get your PHP global version and copy it like this:</p>
<pre><code>php -v
</code></pre><p>Navigate to the directory and replace the 7.4 with the PHP version you copied earlier.</p>
<pre><code>cd /opt/homebrew/etc/php/<span class="hljs-number">7.4</span>/php-fpm.d
</code></pre><p>Create a <code>www.conf</code> file like this:</p>
<pre><code>touch www.conf
</code></pre><p>Open the file so you can add the valet configuration settings:</p>
<pre><code>open -a TextEdit www.conf
</code></pre><p>The command opens up the <code>www.conf</code> file in your text editor and you can update the file with these settings:</p>
<pre><code>pm.max_children = <span class="hljs-number">200</span>
pm.start_servers = <span class="hljs-number">20</span>
pm.min_spare_servers = <span class="hljs-number">10</span>
pm.max_spare_servers = <span class="hljs-number">20</span>
pm.process_idle_timeout = <span class="hljs-number">10</span>s
pm.max_requests = <span class="hljs-number">500</span>
</code></pre><p>Save and close the file from the text editor.</p>
<p>Let's go through each line we added to the <code>www.conf</code> file:</p>
<ul>
<li><strong><code>pm</code></strong> is an acronym for process manager, and the setting will impact how the process manager controls every child process. The possible values available to us include static, on-demand, and dynamic.</li>
<li><strong>pm.max_children</strong> is a static option, indicating the maximum number of the child processes, which we have set to 200.</li>
<li><strong><code>pm.start_servers, pm.max_spare_servers</code></strong> and <code>pm.min_spare_servers</code>: These are dynamic values, and the child processes are set dynamically based on the server directives – that is, start_servers = 20, min_spare_servers = 10 and max_spare_servers = 20.</li>
<li><strong>pm.process_idle_timeout</strong>: the total time taken for an idle request not processed to be killed/terminated is set to a default value of 10 seconds (s). Other units can be estimated in minutes (m), hours (h) or days (d).</li>
<li><strong>pm.max_requests</strong>: This refers to the maximum number of requests a child process can handle at a given time before it's killed/terminated. If the request executes the maximum, it becomes idle, and the pm gets rid of it.</li>
</ul>
<p>Finally, restart all services from the terminal using the sudo brew command. Notice again the 7.4 – that's because of my global PHP version.</p>
<pre><code>sudo brew services restart php@<span class="hljs-number">7.4</span>
</code></pre><p>You can now say bye-bye to the 504 error and slow Valet performance in your local environment.</p>
<h2 id="heading-wrapping-up">Wrapping up</h2>
<p>In this article, you have learned about working with Laravel Valet and how to get all Valet configurations set up. You also learned how to ensure a fast development environment and get rid of persistent 504 gateway timeout errors. </p>
<p>Keep learning and Happy Coding!</p>
<p>You can find me on <a target="_blank" href="https://www.linkedin.com/in/suleolanrewaju/">LinkedIn</a> and <a target="_blank" href="https://twitter.com/bigdevlarry">Twitter</a>.</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ TypeError: can't multiply sequence by non-int of type float [Solved Python Error] ]]>
                </title>
                <description>
                    <![CDATA[ Most times when you encounter errors while coding, you can discover the reason why the error is occurring and how you can fix it in the error message.  The Python error, "TypeError: can't multiply sequence by non-int of type float" is no exception to... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/typeerror-cant-multiply-sequence-by-non-int-of-type-float-solved-python-error-3/</link>
                <guid isPermaLink="false">66adf23c11a28b6eb378d2cb</guid>
                
                    <category>
                        <![CDATA[ error ]]>
                    </category>
                
                    <category>
                        <![CDATA[ error handling ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Python ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Kolade Chris ]]>
                </dc:creator>
                <pubDate>Wed, 21 Dec 2022 21:13:46 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2022/12/pexels-polina-zimmerman-3747132.jpg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>Most times when you encounter errors while coding, you can discover the reason why the error is occurring and how you can fix it in the error message. </p>
<p>The Python error, "TypeError: can't multiply sequence by non-int of type float" is no exception to that.</p>
<p>I have prepared this article to show you why this error occurs and how you can fix it. Read on.</p>
<h2 id="heading-why-the-typeerror-cant-multiply-sequence-by-non-int-of-type-float-error-occurs">Why the "TypeError: can't multiply sequence by non-int of type float" Error Occurs</h2>
<p>To understand why you get the error "TypeError: can't multiply sequence by non-int of type float", let's look at the keywords in the error: <strong>Typeerror</strong>, <strong>multiply</strong>, <strong>sequence</strong>, and <strong>type float</strong>.</p>
<ul>
<li><strong>Typeerror</strong> is an exception thrown when you put together inappropriate data types in an operation</li>
<li><strong>multiply</strong> in the error means you're trying to perform a multiplication</li>
<li><strong>sequence</strong> is an ordered set in Python. It could be strings, lists, or tuples.</li>
<li><strong>type float</strong> means there's a decimal number in the operation you're trying to perform, for example, 2.4 or 5.40</li>
</ul>
<p>So, if you're getting this error, it means you're multiplying any of those sequences (usually a string and a tuple) with a floating point number (decimal number).</p>
<p>Indeed, you can multiply a sequence with a number and Python will do the work properly:</p>
<pre><code class="lang-py">site_name = <span class="hljs-string">'freeCodeCamp '</span>

print(site_name * <span class="hljs-number">2</span>)
<span class="hljs-comment"># freeCodeCamp freeCodeCamp </span>

print(site_name * <span class="hljs-number">3</span>)
<span class="hljs-comment"># freeCodeCamp freeCodeCamp freeCodeCamp</span>
</code></pre>
<pre><code class="lang-py">stringfied_num = <span class="hljs-string">'10 '</span>

print(stringfied_num * <span class="hljs-number">3</span>)
<span class="hljs-comment"># 10 10 10</span>
</code></pre>
<p>Same thing also works for tuples:</p>
<pre><code class="lang-py">myTuple = (<span class="hljs-number">4</span>, <span class="hljs-number">3</span>, <span class="hljs-number">4</span>)
print(myTuple * <span class="hljs-number">2</span>)

<span class="hljs-comment"># (4, 3, 4, 4, 3, 4)</span>
</code></pre>
<p>But if you try to do the multiplication with a decimal point number, you get the error "TypeError: can't multiply sequence by non-int of type float":</p>
<pre><code class="lang-py">site_name = <span class="hljs-string">'freeCodeCamp '</span>

print(site_name * <span class="hljs-number">2.5</span>)
<span class="hljs-comment"># Traceback (most recent call last):  </span>
<span class="hljs-comment">#   File "seq.py", line 3, in &lt;module&gt;</span>
<span class="hljs-comment">#     print(site_name * 2.5)</span>
<span class="hljs-comment"># TypeError: can't multiply sequence by non-int of type 'float'</span>
</code></pre>
<pre><code class="lang-py">myTuple = (<span class="hljs-number">4</span>, <span class="hljs-number">3</span>, <span class="hljs-number">4</span>)
print(myTuple * <span class="hljs-number">2.2</span>)

<span class="hljs-comment"># Traceback (most recent call last):   </span>
<span class="hljs-comment">#   File "seq.py", line 11, in &lt;module&gt;</span>
<span class="hljs-comment">#     print(myTuple * 2.2)</span>
<span class="hljs-comment"># TypeError: can't multiply sequence by non-int of type 'float'</span>
</code></pre>
<h2 id="heading-how-to-fix-the-typeerror-cant-multiply-sequence-by-non-int-of-type-float-error">How to Fix the "TypeError: can't multiply sequence by non-int of type 'float'" Error</h2>
<p>To fix the error "TypeError: can't multiply sequence by non-int of type 'float'", make sure you're not multiplying the string or tuple with a decimal point number. </p>
<p>So instead of multiplying the string or tuple with a floating point number, use an integer. For instance <code>"freeCodeCamp" * 5</code> instead of <code>"freeCodeCamp" * 5.6</code>:</p>
<pre><code class="lang-py">site_name = <span class="hljs-string">'freeCodeCamp '</span>
print(site_name * <span class="hljs-number">5</span>)

<span class="hljs-comment"># freeCodeCamp freeCodeCamp freeCodeCamp freeCodeCamp freeCodeCamp</span>
</code></pre>
<p>If you're dealing with a number in strings, for example, "10", you can convert the string to an integer with the <code>int()</code> method and to float with the <code>float()</code> method:</p>
<pre><code class="lang-py">stringfied_num = <span class="hljs-string">'10 '</span>

print(int(stringfied_num) * <span class="hljs-number">3</span>)
<span class="hljs-comment"># 30</span>
</code></pre>
<pre><code class="lang-py">stringfied_num = <span class="hljs-string">'10 '</span>

print(float(stringfied_num) * <span class="hljs-number">3</span>)
<span class="hljs-comment"># 30</span>
</code></pre>
<p>If you're dealing with a user input, you can also find a way to convert the floating-point number to an integer. In fact, you should handle the possibility of the user entering a decimal point number instead of a straight integer:</p>
<pre><code class="lang-py"><span class="hljs-comment"># declare a string variable</span>
site_name = <span class="hljs-string">'freeCodeCamp '</span>

<span class="hljs-comment"># Get the user input and convert it to a decimal number</span>
user_input = float(input(<span class="hljs-string">"Enter a number: "</span>))

<span class="hljs-comment"># Round the number entered by the user to the nearest whole number</span>
rounded_input = round(user_input)

<span class="hljs-comment"># Multiply the site_name variable by the user input</span>
result = rounded_input * site_name

<span class="hljs-comment"># Print the result to the console</span>
print(result)

<span class="hljs-comment"># I entered 3.6 and the result was: freeCodeCamp freeCodeCamp freeCodeCamp freeCodeCamp</span>
</code></pre>
<h2 id="heading-conclusion">Conclusion</h2>
<p>You cannot multiply a sequence by a floating point number. What you get if you do that is the error, TypeError: can't multiply sequence by non-int of type 'float'. That's why this article was dedicated to letting you know how to fix the error.</p>
<p>The takeaway from this article is that if you're using any string as a number, you should make sure they are converted with the <code>float()</code> method – especially if they are used in a calculation.</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ Cannot use import statement outside a module [React TypeScript Error Solved] ]]>
                </title>
                <description>
                    <![CDATA[ When building a web application, you may encounter the SyntaxError: Cannot use import statement outside a module error.  This error might be raised when using either JavaScript or TypeScript in the back-end. So you could be working on the client side... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/cannot-use-import-statement-outside-a-module-react-typescript-error-solved/</link>
                <guid isPermaLink="false">66b0a27f675b17049e0b4be0</guid>
                
                    <category>
                        <![CDATA[ error ]]>
                    </category>
                
                    <category>
                        <![CDATA[ error handling ]]>
                    </category>
                
                    <category>
                        <![CDATA[ JavaScript ]]>
                    </category>
                
                    <category>
                        <![CDATA[ node ]]>
                    </category>
                
                    <category>
                        <![CDATA[ node js ]]>
                    </category>
                
                    <category>
                        <![CDATA[ TypeScript ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Ihechikara Abba ]]>
                </dc:creator>
                <pubDate>Tue, 15 Nov 2022 15:30:56 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2022/11/markus-spiske-iar-afB0QQw-unsplash.jpg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>When building a web application, you may encounter the <code>SyntaxError: Cannot use import statement outside a module</code> error. </p>
<p>This error might be raised when using either JavaScript or TypeScript in the back-end. So you could be working on the client side with React, Vue, and so on, and still run into this error. </p>
<p>You can also encounter this error when working with JavaScript on the client side. </p>
<p>In this article, you'll learn how to fix the <code>SyntaxError: Cannot use import statement outside a module</code> error when using TypeScript or JavaScript with <a target="_blank" href="https://www.freecodecamp.org/news/node-js-server-side-javascript-what-is-node-used-for/">Node</a>. </p>
<p>You'll also learn how to fix the error when working with JavaScript on the client side. </p>
<h2 id="heading-how-to-fix-the-typescript-syntaxerror-cannot-use-import-statement-outside-a-module-error">How to Fix the TypeScript <code>SyntaxError: Cannot use import statement outside a module</code> Error</h2>
<p>In this section, we'll work with a basic Node server using Express. </p>
<p>Note that if you're using the latest version of TypeScript for your Node app, the <strong>tsconfig.json</strong> file has default rules that prevent the <code>SyntaxError: Cannot use import statement outside a module</code> error from being raised.</p>
<p>So you're most likely not going to encounter the <code>SyntaxError: Cannot use import statement outside a module</code> error if you:</p>
<ul>
<li>Install the latest version of TypeScript, and are using the default <strong>tsconfig.json</strong> file that is generated when you run <code>tsc init</code> with the latest version.</li>
<li>Setup TypeScript correctly for Node and install the necessary packages.</li>
</ul>
<p>But let's assume you're not using the latest <strong>tsconfig.json</strong> file configurations.</p>
<p>Here's an Express server that listens on port 3000 and logs "Hello World!" to the console:</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">import</span> express <span class="hljs-keyword">from</span> <span class="hljs-string">"express"</span>

<span class="hljs-keyword">const</span> app = express()

app.listen(<span class="hljs-string">"3000"</span>, (): <span class="hljs-function"><span class="hljs-params">void</span> =&gt;</span> {
    <span class="hljs-built_in">console</span>.log(<span class="hljs-string">"Hello World!"</span>)
    <span class="hljs-comment">// SyntaxError: Cannot use import statement outside a module</span>
})
</code></pre>
<p>The code above looks as though it should run perfectly but the <code>SyntaxError: Cannot use import statement outside a module</code> is raised. </p>
<p>This is happening because we used the <code>import</code> keyword to import a module: <code>import express from "express"</code>. </p>
<p>To fix this, head over to the <strong>tsconfig.json</strong> file and scroll to the modules section.</p>
<p>You should see a particular rule like this under the modules section:</p>
<pre><code class="lang-javascript"><span class="hljs-comment">/* Modules */</span>
<span class="hljs-string">"module"</span>: <span class="hljs-string">"esnext"</span>
</code></pre>
<p>To fix the problem, change the value "esnext" to "commonjs". </p>
<p>That is:</p>
<pre><code class="lang-javascript"><span class="hljs-comment">/* Modules */</span>
<span class="hljs-string">"module"</span>: <span class="hljs-string">"commonjs"</span>
</code></pre>
<h2 id="heading-how-to-fix-the-javascript-syntaxerror-cannot-use-import-statement-outside-a-module-error">How to Fix the JavaScript <code>SyntaxError: Cannot use import statement outside a module</code> Error</h2>
<p>Fixing the <code>SyntaxError: Cannot use import statement outside a module</code> error when using vanilla JS is a bit different from TypeScript. </p>
<p>Here's our server:</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">import</span> express <span class="hljs-keyword">from</span> <span class="hljs-string">"express"</span>;

<span class="hljs-keyword">const</span> app = express();

app.listen(<span class="hljs-number">3000</span>, <span class="hljs-function">() =&gt;</span> {
    <span class="hljs-built_in">console</span>.log(<span class="hljs-string">"Hello World!"</span>);
    <span class="hljs-comment">// SyntaxError: Cannot use import statement outside a module</span>
});
</code></pre>
<p>We're getting the <code>SyntaxError: Cannot use import statement outside a module</code> error for the same reason — we used the <code>import</code> keyword to import a module. </p>
<p>To fix this, go to the <strong>package.json</strong> file and add <code>"type": "module",</code>. That is:</p>
<pre><code class="lang-javascript">{
  <span class="hljs-string">"name"</span>: <span class="hljs-string">"js"</span>,
  <span class="hljs-string">"version"</span>: <span class="hljs-string">"1.0.0"</span>,
  <span class="hljs-string">"description"</span>: <span class="hljs-string">""</span>,
  <span class="hljs-string">"main"</span>: <span class="hljs-string">"app.js"</span>,
  <span class="hljs-string">"type"</span>: <span class="hljs-string">"module"</span>,
  <span class="hljs-string">"scripts"</span>: {
    <span class="hljs-string">"test"</span>: <span class="hljs-string">"echo \"Error: no test specified\" &amp;&amp; exit 1"</span>
  },
  <span class="hljs-string">"keywords"</span>: [],
  <span class="hljs-string">"author"</span>: <span class="hljs-string">""</span>,
  <span class="hljs-string">"license"</span>: <span class="hljs-string">"ISC"</span>,
  <span class="hljs-string">"dependencies"</span>: {
    <span class="hljs-string">"express"</span>: <span class="hljs-string">"^4.18.2"</span>
  }
}
</code></pre>
<p>Now you can use the <code>import</code> keyword without getting an error.</p>
<p>To fix this error when working with JavaScript on the client side (without any frameworks), simply add the attribute <code>type="module"</code> to the script tag of the file you want to import as a module. That is:</p>
<pre><code>&lt;script type=<span class="hljs-string">"module"</span> src=<span class="hljs-string">"./add.js"</span>&gt;&lt;/script&gt;
</code></pre><h2 id="heading-summary">Summary</h2>
<p>In this article, we talked about the <code>SyntaxError: Cannot use import statement outside a module</code> error in TypeScript and JavaScript. </p>
<p>This error mainly occurs when you use the <code>import</code> keyword to import a module in Node.js. Or when you omit the <code>type="module"</code> attribute in a <code>script</code> tag.</p>
<p>We saw code examples that raised the error and how to fix them when working with TypeScript and JavaScript.</p>
<p>Happy coding!</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ Error: error:0308010c:digital envelope routines::unsupported [Node Error Solved] ]]>
                </title>
                <description>
                    <![CDATA[ If you work with Node.js and command line interface solutions like Webpack, create-react-app, or vue-cli-service, you might have encountered the error, Error: error:0308010c:digital envelope routines::unsupported.  You’re not alone, because I’m curre... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/error-error-0308010c-digital-envelope-routines-unsupported-node-error-solved/</link>
                <guid isPermaLink="false">66adf0c7b0efb2bf012fd7b7</guid>
                
                    <category>
                        <![CDATA[ error ]]>
                    </category>
                
                    <category>
                        <![CDATA[ error handling ]]>
                    </category>
                
                    <category>
                        <![CDATA[ node ]]>
                    </category>
                
                    <category>
                        <![CDATA[ node js ]]>
                    </category>
                
                    <category>
                        <![CDATA[ React ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Kolade Chris ]]>
                </dc:creator>
                <pubDate>Thu, 10 Nov 2022 18:39:19 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2022/11/envelope-1829509_1280.jpg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>If you work with Node.js and command line interface solutions like Webpack, create-react-app, or vue-cli-service, you might have encountered the error, <code>Error: error:0308010c:digital envelope routines::unsupported</code>. </p>
<p>You’re not alone, because I’m currently getting it too:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/11/ss1-1.png" alt="ss1-1" width="600" height="400" loading="lazy"></p>
<p>The React app indeed failed to start:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/11/ss2-1.png" alt="ss2-1" width="600" height="400" loading="lazy"> </p>
<p>In this article, you’ll learn how to fix this error in 3 ways. But first, let’s discuss what causes the error.</p>
<h2 id="heading-what-causes-the-0308010cdigital-envelope-routinesunsupported-error">What Causes the "0308010c:digital envelope routines::unsupported" Error?</h2>
<p>You are likely getting this error because of 2 main reasons:</p>
<ul>
<li>you’re not using the LTS (long term support) version of Node JS. You can see I’m using Node 17.0.0, which is not an LTS version of Node. </li>
<li>you’re using react-script with a version less than 5</li>
</ul>
<p>The error can also occur because you’re using Node 17.</p>
<h2 id="heading-how-to-fix-the-0308010cdigital-envelope-routinesunsupported-error">How to Fix the "0308010c:digital envelope routines::unsupported" Error</h2>
<p>There are at least 3 ways by which you can fix this error. We are going to look at them one by one. Any of them should work for you.</p>
<h3 id="heading-pass-openssl-legacy-provider-to-webpack-or-the-cli-tool">Pass <code>--openssl-legacy-provider</code> to Webpack or the CLI Tool</h3>
<p>In a React app, for instance, you can pass <code>--openssl-legacy-provider</code> to the start script like this <code>"react-scripts --openssl-legacy-provider start"</code>.</p>
<p>That should do it. But if this fails to fix the error, then proceed to the next fix. On many occasions, it works.</p>
<h3 id="heading-use-an-lts-version-of-node-js">Use an LTS Version of Node JS</h3>
<p>Consider downgrading your Node version to 16.16.0 or other LTS versions. </p>
<p>Currently, 18.12.1 is the latest LTS version of Node. You can download it from the Node JS official website or use NVM to install it.</p>
<h3 id="heading-upgrade-react-script-to-version-5">Upgrade React Script to Version 5+</h3>
<p>If you’re working with React and this still fails to fix the error for you, then it’s likely an issue with your React script. </p>
<p>If you’re using a React script version less than 5, then you should upgrade it to version 5+.</p>
<p>In my case, I’m currently using react-scripts 3.4.3:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/11/ss3.png" alt="ss3" width="600" height="400" loading="lazy"> </p>
<p>To upgrade react-scripts to 5+, you can do it in two ways:</p>
<ul>
<li><p>Uninstall and reinstall react-scripts</p>
<ul>
<li>open the terminal and run <code>npm uninstall react-scripts</code></li>
<li>run <code>npm install react-scripts</code></li>
</ul>
</li>
<li><p>Manually change the react script version</p>
<ul>
<li>go to your <code>package.json</code> and change the react-script version to 5.0.2</li>
<li>delete the node_modules folder by running <code>rm –rf node_modules</code></li>
<li>delete the package.lock.json file by running <code>rm –rf package.lock.json</code></li>
<li>run <code>npm install</code> or <code>yarn add</code>, depending on the package manager you’re using</li>
</ul>
</li>
</ul>
<p>After upgrading the version of react-scripts to 5+, my React app is now working fine:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/11/ss4.png" alt="ss4" width="600" height="400" loading="lazy"></p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/11/ss5.png" alt="ss5" width="600" height="400" loading="lazy"> </p>
<h2 id="heading-conclusion">Conclusion</h2>
<p>As already pointed out in this article, if you are getting the "0308010c:digital envelope routines::unsupported" error, then it could happen you’re not using an LTS version of Node JS, or you’re using react-scripts version &lt;5.</p>
<p>Hopefully the fixes we discussed in this tutorial help you fix this error. If any of the fixes fail to work for you, then you should try the others. In my case, upgrading react-scripts to 5+ was what worked for me.</p>
<p>Thank you for reading.</p>
 ]]>
                </content:encoded>
            </item>
        
    </channel>
</rss>
