0

I am trying to get the "Device Name" or node name on my different systems, using this python 3.8.1 code:

import platform
uname = platform.uname()
print(f'Device name: {uname}')

This works as expected on Ubuntu 18.04, but on my 19.04 system I get 'ip-10-0-0-40' rather than the device name -- by device name, I mean the Device Name displayed in the system's details/about section -- the name that I assigned to the system when installing the OS.

I can solve my application's program other ways -- only do X if on system Y -- but now I am curious if this is a Python/Ubuntu 19.04 issue for everyone or it's just my system.

UPDATE: I had an SSH connection open to an EC2 instance at Amazon in one terminal session. When I terminated that connection, I get the expected result -- but even when I was running on a local terminal session. I will probably fallback to an environment variable to avoid this ambiguous result. But would still love to know how to always get the local device name reliably.

kavu
  • 199
  • 2
  • 8
  • 1
    I assume that from the terminal `uname -n` prints the same thing? Since this is the network node name it can be changed by dhcp depending on how the device is configured. This isn't really a python thing. You'll have more luck with superuser.com or serverfault.com. – tdelaney May 16 '20 at 17:41
  • On Linux you could check `/etc/os-release` – txk2048 May 17 '20 at 15:21
  • I just checked and on Ubutnu 19.04, `/etc/os-release` doesn't have the Device Name – kavu May 17 '20 at 16:26

0 Answers0