lsymds / hetznercloud-py

Python SDK for the new Hetzner cloud
MIT License
30 stars 12 forks source link

Error messages not shown #6

Closed nh2 closed 6 years ago

nh2 commented 6 years ago

Right now it doesn't seem to show error messages as returned by Hetzner:

Doing e.g.

server_a, create_action = client.servers().create(name="My required server name", # REQUIRED
    server_type=hetznercloud.SERVER_TYPE_1CPU_2GB, # REQUIRED
    image=hetznercloud.IMAGE_UBUNTU_1604, # REQUIRED
    datacenter=hetznercloud.DATACENTER_FALKENSTEIN_1,
    start_after_create=True,
    ssh_keys=["my SSH key"],
    )
server_a.wait_until_status_is(hetznercloud.SERVER_STATUS_RUNNING)

will print

Traceback (most recent call last):
  File "niklas-test.py", line 57, in <module>
    ssh_keys=["my SSH key"],
  File "/home/niklas/src/hetznercloud-py/hetznercloud/servers.py", line 46, in create
    raise HetznerActionException(result["error"] if result is not None else None)
  File "/home/niklas/src/hetznercloud-py/hetznercloud/exceptions.py", line 31, in __init__
    super().__init__("Failed to perform the requested action: %s" % error_code)
TypeError: super() takes at least 1 argument (0 given)

If before this line https://github.com/elsyms/hetznercloud-py/blob/182caf09f7ed397adeb284662e6e0edcfe6b9dfa/hetznercloud/servers.py#L46

you insert

print(result)

we see:

{u'error': {u'message': u"invalid input in field 'name'", u'code': u'invalid_input', u'details': {u'fields': [{u'messages': [u'name must be a valid hostname'], u'name': u'name'}]}}}

So Hetzner tells us what the error is in error.message, and I guess HetznerActionException(result["error"] if result is not None else None) is supposed to capture that and show it later, but further down the line a function is called with the wrong number of arguments so it crashes and doesn't show it.

nh2 commented 6 years ago

A, I see, this is because in this run I'm using Python 2.7. With Python 3.5 it works.

The project doesn't really say which Python versions are supported; up until client.servers().create everything worked with both 2 and 3 so I assumed that it intends to work on both versions.

ghost commented 6 years ago

Sorry, I'm only intending on supporting Python3. Will add that to the documentation though.