MT5 Python error -6: Authorization failed (RES_E_AUTH_FAILED)
The login, password or server name was refused when connecting the account. Check the exact server name and the password.
What it means
You see this code in mt5.last_error() in Python, after a package call returns None or False.
mt5.initialize() with a login, or mt5.login(), tried to sign the terminal in to the trade account and the broker refused.
Nothing about the account changed. The terminal simply isn't signed in to it.
Common causes
- A wrong or expired password.
- A server name that doesn't match exactly, such as a missing suffix.
- A login number from another broker or another server.
- An account that the broker has closed or archived.
How to fix it
- Copy the server name exactly as the terminal shows it in the login dialog.
- Pass the login as an int and the password and server as strings.
- Keep the password out of your code and logs: read it from the environment.
- Remember an investor password signs in but can't trade.
Example in Python:
import os
import MetaTrader5 as mt5
ok = mt5.initialize(
login=int(os.environ["MT5_LOGIN"]),
password=os.environ["MT5_PASSWORD"], # never print or log it
server=os.environ["MT5_SERVER"],
)
if not ok:
code, _ = mt5.last_error()
print("login failed with code", code) # don't echo the password Is it safe to retry?
Not with the same details. Repeated failed logins can get an account blocked for a while.
Could the order have executed?
Not a trade. A sign in problem, not a trade.
How Tickwire handles it
Tickwire never logs or returns broker passwords. Health shows whether an account is connected, with the reason in plain words when it isn't. See health.
Related codes
- MT5 Python error -10003: IPC initialize failed (RES_E_INTERNAL_FAIL_INIT)
- MT5 error 10017: Trade is disabled (TRADE_RETCODE_TRADE_DISABLED)
- MT5 Python error -10004: No IPC connection (RES_E_INTERNAL_FAIL_CONNECT)
Related MT5 Python functions
One API for MT4 and MT5
Clear trade outcomes, idempotent orders and an audit log. Read the error reference or the quickstart.