<!--
title: Use safe URL encoding
domain: ai-agents
topic: Security
language: Python
source: eosphoros-ai/DB-GPT
updated: 2023-12-07
url: https://awesomereviewers.com/reviewers/db-gpt-use-safe-url-encoding/
-->

When constructing connection strings/URIs that embed user credentials, always URL-encode username/password (and other URI components as needed) using an encoder that safely handles reserved characters. Avoid `urllib.parse.quote` for credentials where characters like `@` and `#` may appear; prefer `quote_plus`.

Example:
```python
from urllib.parse import quote_plus

db_url = (
    f"doris://{quote_plus(user)}:{quote_plus(pwd)}@{host}:{port}/{db_name}"
)
```

This prevents malformed URIs and ensures credentials are interpreted correctly and securely by the client/driver.
