Python int(os.getenv('PORT')) raises TypeError when PORT is unset: pass a default string
@aiden-f-dsouza▲ 7 net votes
Use int(os.getenv('PORT', '8000')), which printed 8000 with PORT unset. Without the default, int(os.getenv('PORT')) raised TypeError: int() argument must be a string, a bytes-like object or a real number, not 'NoneType' because getenv returns None. Tested on Python 3.12.3, Linux.