The most common questions for Back-End Learners

In this article we address the six most common questions asked by learners  on the Back-End course. 

  1. How can I troubleshoot and resolve issues with Wincpy while using Python?
  2. How do I use Git to upload my code to GitHub from the command line?
  3. What is the difference between the GitHub SSH key and the Droplet SSH key
  4. Why is my Python code not running or throwing errors
  5. Why am I unable to connect to my Droplet/VPS server on 127.0.0.1? 
  6. How can I resolve the 'ModuleNotFoundError: No module named 'pytest'' error in Python?"

Whether you're new to back-end development or need clarification on specific concepts, this article tries to provide answers to help you navigate the course material. If you have further questions, our support team is available via chat, and our FAQ/knowledge base is a valuable resource. 

1. How can I troubleshoot and resolve issues with Wincpy while using Python?

When encountering issues with Wincpy while using Python, there are several troubleshooting steps you can follow:

  • Ensure that your file is saved properly before running Wincpy.
  • Test if your code runs correctly without Wincpy to isolate the issue.
  • Place print statements inside your function to check if the values are being added correctly.
  • Remember to use the return statement instead of print for the final result in your function. Here's an example:

Then, it's important to note that functions are not executed automatically in Wincpy; you need to call them from outside the function as shown in the example with calculation(3, 7).

Did you receive an error that looks like  the one below? This error indicates that Wincpy expects the function 'calculation' to exist in your code. It should take two arguments (in this case, 3 and 7) and return 10.


2. How do I use Git to upload my code to GitHub from the command line?

To upload your code to GitHub from the command line using Git, you can follow these step-by-step instructions. By using Git commands, you can easily create a repository, add your GitHub repository as the remote origin, prepare your files for upload, commit your changes with a message, and finally push your code to GitHub. Let's dive into the details of each step.

Step 1: Create repository locally (this is only needed the first time)
git init
Step 2: Add your GitHub repository locally
git remote add origin https://github.com/username/repository-name.git
Step 3: Prepare the file(s) you want to upload
git add index.html
git add different_file.txt
Step 4: Write down what you changed (e.g. fixed a typo)
git commit -m "Fixed the typo"
Step 5: Upload the code to GitHub
git push

*Note that if this is your first time using git push, you may need to set the branch using: git push --set-upstream origin master


Furthermore you can find Additional Git operations that might interest you below.

Step 1: Change the repository url
git remote set-url origin https://github.com/username/second-repository.git
Step 2: Delete the file styles.css from Git:
git rm --cached style.css
git commit -m "Removed CSS file style.css"
git push

Step 3: Delete the folder named ‘not_so_important_folder’  from Git:
git rm --cached -r not_so_important_folder
git commit -m "Removed the folder not_so_important_folder"
git push

3. What is the difference between the GitHub SSH key and the Droplet SSH key


The GitHub SSH key and the Droplet SSH key serve different purposes in the context of code deployment and server access.

The SSH key used to sign Git code is a cryptographic key pair that is used to verify the authenticity of the code changes made by a specific user. When you commit changes to a Git repository, you can sign those changes with your SSH key to prove that you are the person who made those changes. This helps to ensure the integrity of the codebase and prevent unauthorized changes.

On the other hand, the SSH key used to connect to a server is a cryptographic key pair that is used to authenticate and authorize access to a remote server. When you connect to a server using SSH, the server will ask for your SSH key to verify that you are authorized to access the system. This helps to ensure that only authorized users can access the server, and helps to prevent unauthorized access or malicious activity.

By using GitHub Actions to deploy to a server, you can automate the build and deployment process of your code. This allows you to easily and efficiently deploy your code to your server without having to manually perform the steps. The SSH key used for server access in this context is separate from the SSH key used for signing Git code changes.

Understanding the difference between the GitHub SSH key and the Droplet SSH key is crucial for effective code deployment and secure server access. By using the appropriate SSH keys for their respective purposes, you can ensure code integrity, protect against unauthorized access, and streamline your deployment processes.

4. Why is my Python code not running or throwing errors?


When your Python code is not running or throwing errors, there could be a few reasons behind this issue. Here are some troubleshooting steps you can take:

Firstly, if you are running your code with wincpy and encounter errors, you can use the following command to check for errors:

For Windows users, if you encounter an error, try including a '&' symbol in front of the Python command, like this:

& python –version

or try:

& python -m wincpy check <id>

If you are unable to find the Python command, ensure that you have checked the option 'Add Python 3.x to PATH' during the Python installation process. After installation, restart Powershell or VSCode for the changes to take effect.

By following these steps, you can diagnose and resolve issues with running Python code or encountering errors.

5. Why am I unable to connect to my Droplet/VPS server on 127.0.0.1? 


If you are unable to connect to your Droplet/VPS server on 127.0.0.1, it is because 127.0.0.1 is a local IP address that refers to the "loopback" interface on your own device. Local IP addresses, such as 127.0.0.1 and localhost, are comparable to 'Home' as they are unique to each device on a local network. They are used for internal communication within your device.

When it comes to accessing your server remotely, you should use the server's public IP address instead. The public IP address is the address that identifies your server on the internet and allows external devices to connect to it. To find your server's public IP address, you can run the command ip a on the server itself or check in the DigitalOcean panel where you can find the IP address associated with your Droplet.

Using the public IP address, you can connect to your server from a different device or network. Make sure to configure any necessary firewall rules or network settings to allow incoming connections to the server on the desired ports.

By using the correct public IP address instead of 127.0.0.1, you will be able to connect to your Droplet/VPS server remotely and access the services hosted on it.

6. How can I resolve the 'ModuleNotFoundError: No module named 'pytest'' error in Python?


The 'ModuleNotFoundError: No module named 'pytest'' error occurs when you try to run a Python script that relies on the pytest module, but the module is not installed on your system. Python modules are libraries or packages that provide additional functionality to your code. When a module is not found, it means that Python cannot locate the necessary files to import and use that module.

To resolve this error, you need to install the pytest module using a package manager like pip. Here are the steps to follow:

  1. Open a command prompt or terminal window on your computer.
  2. Once you have the command prompt or terminal open, you can use the following command: pip install pytest and press Enter to execute the command.
  3. Wait for the installation to complete. You will see some output indicating the progress of the installation.
  4. Once the installation is finished, try running your Python script again.

 

We hope you have found this FAQ article useful and we encourage you to explore the rest of it. For any remaining questions or concerns, we like to refer you to our Support Center. Furthermore, we appreciate your feedback, as it helps us improve. Please take a moment to fill out this form and share your thoughts. Happy learning!