Step1: I have a EC2 instance(Instance 1) where my custom app is hosted in production mode and it works fine
Step2: and I’ve created an AMI from Instance 1
Step3: now, whenever I launch a new EC2 instance(Instance2) from the AMI created in Step2, I’m always facing this issue:
“pymysql.err.OperationalError: (1045, “Access denied for user ‘_f166f15b655fbd77’@‘172.31.24.122’ (using password: YES)”)”
the issue occurs only for Instance2 but Instance1 works fine.
note: I’m using AWS RDS(mariadb) and not local MySQL
extended log:
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File “/home/ubuntu/myfrappe/env/lib/python3.8/site-packages/gunicorn/workers/sync.py”, line 136, in handle
self.handle_request(listener, req, client, addr)
File “/home/ubuntu/myfrappe/env/lib/python3.8/site-packages/gunicorn/workers/sync.py”, line 179, in handle_request
respiter = self.wsgi(environ, resp.start_response)
File “/home/ubuntu/myfrappe/env/lib/python3.8/site-packages/werkzeug/local.py”, line 354, in application
return ClosingIterator(app(environ, start_response), self.cleanup)
File “/home/ubuntu/myfrappe/env/lib/python3.8/site-packages/werkzeug/wrappers/request.py”, line 206, in application
resp = f(*args[:-2] + (request,))
File “/home/ubuntu/myfrappe/apps/frappe/frappe/app.py”, line 87, in application
response = handle_exception(e)
File “/home/ubuntu/myfrappe/apps/frappe/frappe/app.py”, line 268, in handle_exception
response = get_response(“message”, http_status_code=http_status_code)
File “/home/ubuntu/myfrappe/apps/frappe/frappe/website/serve.py”, line 23, in get_response
response = ErrorPage(exception=e).render()
File “/home/ubuntu/myfrappe/apps/frappe/frappe/website/page_renderers/error_page.py”, line 6, in init
super().init(path=path, http_status_code=http_status_code)
File “/home/ubuntu/myfrappe/apps/frappe/frappe/website/page_renderers/template_page.py”, line 28, in init
self.set_template_path()
File “/home/ubuntu/myfrappe/apps/frappe/frappe/website/page_renderers/template_page.py”, line 36, in set_template_path
for app in frappe.get_installed_apps(frappe_last=True):
File “/home/ubuntu/myfrappe/apps/frappe/frappe/init.py”, line 1099, in get_installed_apps
installed = json.loads(db.get_global(“installed_apps”) or “”)
File “/home/ubuntu/myfrappe/apps/frappe/frappe/database/database.py”, line 813, in get_global
return self.get_default(key, user)
File “/home/ubuntu/myfrappe/apps/frappe/frappe/database/database.py”, line 817, in get_default
d = self.get_defaults(key, parent)
File “/home/ubuntu/myfrappe/apps/frappe/frappe/database/database.py”, line 835, in get_defaults
defaults = frappe.defaults.get_defaults(parent)
File “/home/ubuntu/myfrappe/apps/frappe/frappe/defaults.py”, line 77, in get_defaults
globald = get_defaults_for()
File “/home/ubuntu/myfrappe/apps/frappe/frappe/defaults.py”, line 193, in get_defaults_for
res = frappe.qb.from_(table).where(
File “/home/ubuntu/myfrappe/apps/frappe/frappe/query_builder/utils.py”, line 62, in execute_query
return frappe.db.sql(query, params, *args, **kwargs) # nosemgrep
File “/home/ubuntu/myfrappe/apps/frappe/frappe/database/database.py”, line 131, in sql
self.connect()
File “/home/ubuntu/myfrappe/apps/frappe/frappe/database/database.py”, line 75, in connect
self._conn = self.get_connection()
File “/home/ubuntu/myfrappe/apps/frappe/frappe/database/mariadb/database.py”, line 75, in get_connection
conn = pymysql.connect(
File “/home/ubuntu/myfrappe/env/lib/python3.8/site-packages/pymysql/connections.py”, line 353, in init
self.connect()
File “/home/ubuntu/myfrappe/env/lib/python3.8/site-packages/pymysql/connections.py”, line 633, in connect
self._request_authentication()
File “/home/ubuntu/myfrappe/env/lib/python3.8/site-packages/pymysql/connections.py”, line 907, in _request_authentication
auth_packet = self._read_packet()
File “/home/ubuntu/myfrappe/env/lib/python3.8/site-packages/pymysql/connections.py”, line 725, in _read_packet
packet.raise_for_error()
File “/home/ubuntu/myfrappe/env/lib/python3.8/site-packages/pymysql/protocol.py”, line 221, in raise_for_error
err.raise_mysql_exception(self._data)
File “/home/ubuntu/myfrappe/env/lib/python3.8/site-packages/pymysql/err.py”, line 143, in raise_mysql_exception
raise errorclass(errno, errval)
pymysql.err.OperationalError: (1045, “Access denied for user ‘_f166f15b655fbd77’@‘172.31.24.122’ (using password: YES)”)
[2022-04-19 19:21:44 +0000] [1015] [ERROR] Error handling request /
Traceback (most recent call last):
File “/home/ubuntu/myfrappe/apps/frappe/frappe/app.py”, line 52, in application
init_request(request)
File “/home/ubuntu/myfrappe/apps/frappe/frappe/app.py”, line 128, in init_request
frappe.local.http_request = frappe.auth.HTTPRequest()
File “/home/ubuntu/myfrappe/apps/frappe/frappe/auth.py”, line 32, in init
self.set_session()
File “/home/ubuntu/myfrappe/apps/frappe/frappe/auth.py”, line 69, in set_session
frappe.local.login_manager = LoginManager()
File “/home/ubuntu/myfrappe/apps/frappe/frappe/auth.py”, line 123, in init
self.make_session(resume=True)
File “/home/ubuntu/myfrappe/apps/frappe/frappe/auth.py”, line 205, in make_session
frappe.local.session_obj = Session(user=self.user, resume=resume,
File “/home/ubuntu/myfrappe/apps/frappe/frappe/sessions.py”, line 213, in init
self.resume()
File “/home/ubuntu/myfrappe/apps/frappe/frappe/sessions.py”, line 279, in resume
validate_ip_address(self.user)
File “/home/ubuntu/myfrappe/apps/frappe/frappe/auth.py”, line 389, in validate_ip_address
user = frappe.get_cached_doc(“User”, user) if not frappe.flags.in_test else frappe.get_doc(“User”, user)
File “/home/ubuntu/myfrappe/apps/frappe/frappe/init.py”, line 875, in get_cached_doc
doc = get_doc(*args, **kwargs)
File “/home/ubuntu/myfrappe/apps/frappe/frappe/init.py”, line 939, in get_doc
doc = frappe.model.document.get_doc(*args, **kwargs)
File “/home/ubuntu/myfrappe/apps/frappe/frappe/model/document.py”, line 74, in get_doc
controller = get_controller(doctype)
File “/home/ubuntu/myfrappe/apps/frappe/frappe/model/base_document.py”, line 70, in get_controller
site_controllers[doctype] = _get_controller()
File “/home/ubuntu/myfrappe/apps/frappe/frappe/model/base_document.py”, line 34, in _get_controller
module_name, custom = frappe.db.get_value(
File “/home/ubuntu/myfrappe/apps/frappe/frappe/database/database.py”, line 391, in get_value
result = self.get_values(doctype, filters, fieldname, ignore, as_dict, debug,
File “/home/ubuntu/myfrappe/apps/frappe/frappe/database/database.py”, line 463, in get_values
out = self._get_values_from_table(
File “/home/ubuntu/myfrappe/apps/frappe/frappe/database/database.py”, line 677, in _get_values_from_table
r = self.sql(
File “/home/ubuntu/myfrappe/apps/frappe/frappe/database/database.py”, line 131, in sql
self.connect()
File “/home/ubuntu/myfrappe/apps/frappe/frappe/database/database.py”, line 75, in connect
self._conn = self.get_connection()
File “/home/ubuntu/myfrappe/apps/frappe/frappe/database/mariadb/database.py”, line 75, in get_connection
conn = pymysql.connect(
File “/home/ubuntu/myfrappe/env/lib/python3.8/site-packages/pymysql/connections.py”, line 353, in init
self.connect()
File “/home/ubuntu/myfrappe/env/lib/python3.8/site-packages/pymysql/connections.py”, line 633, in connect
self._request_authentication()
File “/home/ubuntu/myfrappe/env/lib/python3.8/site-packages/pymysql/connections.py”, line 907, in _request_authentication
auth_packet = self._read_packet()
File “/home/ubuntu/myfrappe/env/lib/python3.8/site-packages/pymysql/connections.py”, line 725, in _read_packet
packet.raise_for_error()
File “/home/ubuntu/myfrappe/env/lib/python3.8/site-packages/pymysql/protocol.py”, line 221, in raise_for_error
err.raise_mysql_exception(self._data)
File “/home/ubuntu/myfrappe/env/lib/python3.8/site-packages/pymysql/err.py”, line 143, in raise_mysql_exception
raise errorclass(errno, errval)
pymysql.err.OperationalError: (1045, “Access denied for user ‘_f166f15b655fbd77’@‘172.31.24.122’ (using password: YES)”)
any inputs would be really helpful!