Describe the bug
As of Python 3.13, getpass.getuser now raises OSError on any failures instead of KeyError. This means that this line doesn't work anymore, and the library crashes on import.
PyMySQL fixed this issue in this commit: PyMySQL/PyMySQL@a1ac823
To Reproduce
- Import aiomysql inside a Docker container with Python 3.13+ with the UID set to something without a username.
- Observe crash.
Expected behavior
It does not crash.
Logs/tracebacks
Traceback (most recent call last):
File "/usr/local/lib/python3.13/getpass.py", line 173, in getuser
return pwd.getpwuid(os.getuid())[0]
~~~~~~~~~~~~^^^^^^^^^^^^^
KeyError: 'getpwuid(): uid not found: 8459'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "<frozen runpy>", line 198, in _run_module_as_main
File "<frozen runpy>", line 88, in _run_code
File "/app/lib/python3.13/site-packages/package/__main__.py", line 1, in <module>
from package import main
File "/app/lib/python3.13/site-packages/package/esc_dl.py", line 17, in <module>
import aiomysql
File "/app/lib/python3.13/site-packages/aiomysql/__init__.py", line 32, in <module>
from .connection import Connection, connect
File "/app/lib/python3.13/site-packages/aiomysql/connection.py", line 42, in <module>
DEFAULT_USER = getpass.getuser()
File "/usr/local/lib/python3.13/getpass.py", line 175, in getuser
raise OSError('No username set in the environment') from e
OSError: No username set in the environment
Python Version
$ python --version
Python 3.13.9
aiomysql Version
$ python -m pip show aiomysql
Name: aiomysql
Version: 0.3.2
Location: /package/.venv/lib/python3.13/site-packages
Requires: pymysql
Required-by: ...
PyMySQL Version
$ python -m pip show PyMySQL
Name: pymysql
Version: 1.1.2
Location: /package/.venv/lib/python3.13/site-packages
Requires:
Required-by: aiomysql
SQLAlchemy Version
$ python -m pip show sqlalchemy
N/A
OS
Linux 6.8.0-84-generic #84-Ubuntu SMP PREEMPT_DYNAMIC Fri Sep 5 22:36:38 UTC 2025 x86_64 x86_64 x86_64 GNU/Linux
Database type and version
Additional context
No response
Code of Conduct
Describe the bug
As of Python 3.13,
getpass.getusernow raises OSError on any failures instead of KeyError. This means that this line doesn't work anymore, and the library crashes on import.PyMySQL fixed this issue in this commit: PyMySQL/PyMySQL@a1ac823
To Reproduce
Expected behavior
It does not crash.
Logs/tracebacks
Python Version
aiomysql Version
PyMySQL Version
SQLAlchemy Version
OS
Linux 6.8.0-84-generic #84-Ubuntu SMP PREEMPT_DYNAMIC Fri Sep 5 22:36:38 UTC 2025 x86_64 x86_64 x86_64 GNU/Linux
Database type and version
Additional context
No response
Code of Conduct