> For the complete documentation index, see [llms.txt](https://falah.gitbook.io/byethost-support/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://falah.gitbook.io/byethost-support/tool-issues-and-fixes/python-tools-common-runtime-errors-and-fixespage-1.md).

# 📘 Python Tools – Common Runtime Errors & FixesPage 1

Useful when using or troubleshooting any Python-based tool (CLI, GUI, automation, bots, etc.)

#### ⚠️ `1. ModuleNotFoundError`

**💬 Message:**

```
ModuleNotFoundError: No module named 'XXXX'
```

**🧠 Cause:**

Missing dependency.

**✅ Fix:**

Install it using `pip`:

```bash
pip3 install XXXX
```

> Replace `XXXX` with the missing module name.

***

#### ⚠️ `2. FileNotFoundError`

**💬 Message:**

```
FileNotFoundError: [Errno 2] No such file or directory: 'data.txt'
```

**🧠 Cause:**

Tool requires a specific file or path that is missing or misnamed.

**✅ Fix:**

* Make sure all required files (`config.py`, `data.txt`, `account_list.txt`, etc.) are present.
* Use relative paths correctly or set full paths.

***

#### ⚠️ `3. SyntaxError`

**💬 Message:**

```
SyntaxError: invalid syntax
```

**🧠 Cause:**

Using wrong syntax or running a script with Python 2 instead of Python 3.

**✅ Fix:**

* Make sure you run with Python 3:

```bash
python3 script.py
```

* Validate your syntax (commas, colons, indentation, etc.).

***

#### ⚠️ `4. IndentationError`

**💬 Message:**

```
IndentationError: unexpected indent
```

**🧠 Cause:**

Inconsistent spaces/tabs.

**✅ Fix:**

Use the same indentation style (4 spaces or tabs). Avoid mixing both.

***

#### ⚠️ `5. KeyboardInterrupt` (Script stops on its own)

**💬 Message:**

```
KeyboardInterrupt
```

**🧠 Cause:**

* User manually pressed `Ctrl + C`.
* Script is stuck or unresponsive.

**✅ Fix:**

* Ignore if intentional.
* Otherwise, check for infinite loops or long `sleep()` calls.

***

#### ⚠️ `6. PermissionError`

**💬 Message:**

```
PermissionError: [Errno 13] Permission denied: 'file.txt'
```

**🧠 Cause:**

You’re trying to write to a file/folder you don’t have access to.

**✅ Fix:**

* Run as administrator or use:

```bash
sudo python3 script.py
```

* Or change file permissions:

```bash
chmod +x file.py
```

***

#### ⚠️ `7. UnicodeEncodeError / DecodeError`

**💬 Message:**

```
UnicodeEncodeError: 'ascii' codec can't encode character
```

**🧠 Cause:**

The script is trying to read/write text that contains special or non-ASCII characters.

**✅ Fix:**

Add this to the top of your script:

```python
# -*- coding: utf-8 -*-
```

Or use:

```python
open("file.txt", "w", encoding="utf-8")
```

***

#### ⚠️ `8. ImportError`

**💬 Message:**

```
ImportError: cannot import name 'XYZ'
```

**🧠 Cause:**

Wrong import structure or circular import.

**✅ Fix:**

* Make sure module exists.
* Don’t name your file with the same name as a module (e.g., `requests.py`).

***

#### ⚠️ `9. AttributeError`

**💬 Message:**

```
AttributeError: 'NoneType' object has no attribute 'send_keys'
```

**🧠 Cause:**

Trying to use a method on something that doesn't exist (e.g., element not found).

**✅ Fix:**

* Check your selectors or variables.
* Always verify that the value is not `None`.

***

#### ⚠️ `10. ConnectionError / Timeout / ProxyError`

**💬 Message:**

```
requests.exceptions.ConnectionError
requests.exceptions.ProxyError
```

**🧠 Cause:**

* Internet disconnected
* Proxy dead
* Wrong URL

**✅ Fix:**

* Test proxy manually
* Ensure valid internet
* Catch the exception:

```python
try:
    requests.get(url, timeout=10)
except requests.exceptions.RequestException:
    print("Connection failed")
```

***

### 🧪 Bonus: Tips Before Running Any Tool

* ✅ Use virtual environments:

```bash
python3 -m venv venv
source venv/bin/activate  # on Linux
.\venv\Scripts\activate   # on Windows
```

* ✅ Always install:

```bash
pip3 install -r requirements.txt
```

* ✅ Make sure your Python version is 3.6+

```bash
python3 --version
```

***
