Skip to content

Trailing Slash Needed #7

@jzhang-sre

Description

@jzhang-sre

dev42._delete('ips/%s' % d_ip['id'])

While implementing the script into our environment, I hit an error when the script tries to delete IP addresses. Testing the issue using a REST API tool yields the same result. POST is able to pull the correct entry but DELETE throws an error.

REST result:

{
"msg": "DELETE 404",
"code": 2
}

puppetexplore.py result:

021-01-29 20:24:19,486 ERROR Error(<class 'device42.Device42HTTPError'>) updating device <server>
Traceback (most recent call last):
File "/opt/inventory_sync/puppetexplore.py", line 369, in d42_update
dev42._delete('ips/%s' % d_ip['id'])
File "/opt/inventory_sync/device42.py", line 68, in _delete
return self._send("DELETE", path)
File "/opt/inventory_sync/device42.py", line 50, in _send
(method, path, resp.status_code, resp.text, data))
Device42HTTPError: HTTP DELETE (ips/2438) Error 500: {"msg": "DELETE 404", "code": 2} request was None

Adding a trailing slash to the API path for DELETE fixes this issue. Suggested change:

dev42._delete('ips/%s/' % d_ip['id'])

Or the following could possibly work also but that assumes other API DELETE paths require trailing slashes:

def _delete(self, path):
return self._send("DELETE", path)

    def _delete(self, path):
        if not path.endswith('/'):
            path += '/'
        return self._send("DELETE", path)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions