f5-common-python icon indicating copy to clipboard operation
f5-common-python copied to clipboard

Error 400 when trying to export ASM Policy with python.

Open jassouline opened this issue 7 years ago • 1 comments

Hi ! I have always the same 400 error when i'm trying this script : ` #!/bin/python2.7 from f5.bigip import ManagementRoot

IP="127.0.0.1" user="admin" password="admin" port_used=8080

mgmt = ManagementRoot(IP, user, password, port=port_used)

#Retrieve Version version = mgmt.tmos_version

#Retrieve all polciies policies = mgmt.tm.asm.policies_s.get_collection() for policy in policies : print policy.name print policy.selfLink

task=mgmt.tm.asm.tasks.export_policy_s.export_policy.create(filename="test.xml", policyReference=policy.selfLink) `

It gives me this error : jassouline@jassouline-ubuntu14:~/f5$ python script_ASM.py Security_policy_test https://localhost/mgmt/tm/asm/policies/v8YKRX-XAZqspOxmJdmAzQ?ver=12.1.2 Traceback (most recent call last): File "script_ASM.py", line 21, in <module> task=mgmt.tm.asm.tasks.export_policy_s.export_policy.create(filename="test.xml", policyReference=policy.selfLink) File "/usr/local/lib/python2.7/dist-packages/f5/bigip/resource.py", line 1053, in create return self._create(**kwargs) File "/usr/local/lib/python2.7/dist-packages/f5/bigip/resource.py", line 1015, in _create response = session.post(_create_uri, json=kwargs, **requests_params) File "/usr/local/lib/python2.7/dist-packages/icontrol/session.py", line 287, in wrapper raise iControlUnexpectedHTTPError(error_message, response=response) icontrol.exceptions.iControlUnexpectedHTTPError: 400 Unexpected Error: Bad Request for uri: https://127.0.0.1:8080/mgmt/tm/asm/tasks/export-policy/ Text: u'{"code":400,"message":"Could not add the Export Policy Task \'Export Policy Task (UNNAMED)\'. Failed validating value \'\' for policy: The value is empty","originalRequestBody":"{\\"policyReference\\": \\"https://localhost/mgmt/tm/asm/policies/v8YKRX-XAZqspOxmJdmAzQ?ver=12.1.2\\", \\"filename\\": \\"test.xml\\"","referer":"172.16.101.91","restOperationId":1930162,"kind":":resterrorresponse"}' jassouline@jassouline-ubuntu14:~/f5$

Thanks in advance.

jassouline avatar Oct 09 '18 08:10 jassouline

You may need to specfiy a "name" value in your argument list to create().

vsnine avatar Oct 09 '18 22:10 vsnine