How to get a user key through CLI in Marzban?
I need to get a Marzban user key specifically through the command line interface (CLI). When I run the command:
marzban cli subscription get-config -u user -f v2ray --base64
I get a JSON file structure, but an error also occurs:
TypeError: generate_subscription() missing 1 required positional argument: 'reverse'
The user key itself is not obtained.
The marzban update command supposedly updates the version, but I don’t know to which version. The marzban status command doesn’t output any information except the “running” status. The core version is 25.8.3.
How do I properly get a user key through CLI in Marzban and how do I solve the error with the ‘reverse’ argument?
Getting User Keys via CLI in Marzban: Complete Guide
To get a user key via CLI in Marzban, you need to use the correct command syntax and resolve the issue with the ‘reverse’ argument. Here’s a detailed solution:
Table of Contents
- Correct command for getting user key
- Solving the ‘reverse’ argument error
- Checking Marzban version
- Alternative methods for getting keys
- Troubleshooting other problems
Correct command for getting user key
The main command to get a user’s configuration through Marzban CLI:
marzban cli subscription get-config -u <username> -f [v2ray|clash] --base64
Where:
<username>- username in your Marzban system-f v2ray- v2ray format (clash is also supported)--base64- output in base64 format
If you want to save the result to a file:
marzban cli subscription get-config -u <username> -f v2ray -o config.json
Important: Make sure you have administrator rights to execute this command and that the user exists in the Marzban system.
Solving the ‘reverse’ argument error
The error TypeError: generate_subscription() missing 1 required positional argument: 'reverse' occurs due to changes in the Marzban API. Here are several ways to solve it:
1. Update Marzban to the latest version
This error often occurs in older versions. Update Marzban:
pip install --upgrade marzban
2. Using environment variables
Add to your .env file or set through environment variable:
export USE_CUSTOM_JSON_DEFAULT=True
3. Check configuration
Make sure your configuration file is set up correctly. According to Marzban documentation, add to .env:
# For v2rayNG
USE_CUSTOM_JSON_FOR_V2RAYNG=True
# For other clients
USE_CUSTOM_JSON_FOR_V2RAYN=False
USE_CUSTOM_JSON_FOR_STREISAND=False
4. Alternative command syntax
Try using an alternative command format:
marzban subscription get-config -u <username> -f v2ray --base64
5. If the problem persists
If the error remains, it might be related to a specific version. Check issue #886 on GitHub where similar v2ray configuration problems are discussed.
Checking Marzban version
To check the Marzban and core version, use the following commands:
Check Marzban CLI version:
marzban --version
Check status and version:
marzban status
Core version information:
The core version (25.8.3) is indicated during installation. To check the installed version:
xray version
Check via pip:
pip show marzban
Alternative methods for getting keys
If CLI doesn’t work, you can get the user key through other methods:
1. Through Marzban web interface
- Go to the Marzban web panel
- Navigate to the “Users” section
- Find the desired user
- Copy the subscription link
2. Through Marzban API
Use the API to get the configuration:
curl -X GET "http://localhost:8000/api/user/<username>/subscription/v2ray" \
-H "accept: application/json" \
-H "Authorization: Bearer <your_token>"
3. Through Telegram bot
If you have a Telegram bot configured for Marzban, you can get the key through the bot.
Troubleshooting other problems
1. Permission issues
If CLI commands don’t work, check user permissions:
sudo -u <user_marzban_is_running_as> marzban cli subscription get-config -u test -f v2ray
2. Configuration issues
Restart Marzban after making configuration changes:
marzban restart
3. Error logging
For more detailed error analysis, enable verbose logging:
marzban cli subscription get-config -u test -f v2ray --verbose
4. Check dependencies
Make sure all required dependencies are installed:
pip install -r requirements.txt
Sources
- Marzban CLI Documentation - Official
- Marzban Configuration Guide
- GitHub - Marzban CLI Commands
- Issue #886 - QUIC bugs and subscription problems
- Marzban Changelog - Version 0.7.0 fixes
- Neonode.cc - Marzban CLI Tutorial
Conclusion
- Main command for getting a user key:
marzban cli subscription get-config -u <username> -f v2ray --base64 - ‘reverse’ argument error is usually resolved by updating Marzban or setting environment variables
- Version check through
marzban --versionandpip show marzban - Alternative methods include web interface and API for getting keys
- Error prevention - regular updates and configuration checks
If the problem persists, it’s recommended to check GitHub issues or contact the Marzban community for more specific help regarding your version and configuration.