F5Networks / f5-icontrol-rest-python

Generic python library used by the F5 SDK and other F5 projects to communicate with BIG-IP® via the REST API
http://icontrol.readthedocs.org/en/latest/
Apache License 2.0
36 stars 32 forks source link

URI not being properly encoded #131

Closed edarzins closed 4 years ago

edarzins commented 7 years ago

When trying to access a node resource with a name of "172.16.1.5%0" on a BIG-IP, the BIG-IP returned an error.

Bad Request for uri: https://10.190.21.52:443/mgmt/tm/ltm/node/~test~172.16.1.5%0

It appears that the URI is not being encoded, the "%" in the node name should be encoded to "%25" before it's sent to the BIG-IP.

jasonrahm commented 5 years ago

@edarzins I know this is old but I'm trying to clean up. Using the route domain address as the node name is probably pretty rare. I'd just do the encoding for the name as part of your code. Directly for this library, that would look like:

>>> from icontrol.session import iControlRESTSession
>>> import urllib

>>> b = iControlRESTSession('admin', 'admin')
>>> partition = 'test'
>>> name = '172.16.1.5%0'
>>> encoded_name = urllib.quote(name)
>>> node = b.get('https://localhost:13443/mgmt/tm/ltm/node/~{}~{}'.format(partition, encoded_name))
>>> node.text
u'{"kind":"tm:ltm:node:nodestate","name":"172.16.1.5%0","partition":"test","fullPath":"/test/172.16.1.5%0","generation":1443,"selfLink":"https://localhost/mgmt/tm/ltm/node/~test~172.16.1.5%250?ver=13.1.1.4","address":"172.16.1.5","connectionLimit":0,"dynamicRatio":1,"ephemeral":"false","fqdn":{"addressFamily":"ipv4","autopopulate":"disabled","downInterval":5,"interval":"3600"},"logging":"disabled","monitor":"default","rateLimit":"disabled","ratio":1,"session":"user-enabled","state":"unchecked"}'

However, if this isn't as rare as I think, I can try to add a check for the name kwarg and encode them appropriately.

f5-rahm commented 4 years ago

archiving this repo, this request will not be implemented.