marksull / fmcapi

A Python package designed to help users of Cisco's FMC interface with its API.
BSD 3-Clause "New" or "Revised" License
81 stars 57 forks source link

GET operation on AccessRules fail #177

Closed wollmannbruno closed 9 months ago

wollmannbruno commented 9 months ago

Describe the bug A GET operation on AccessRules fails.

To Reproduce Here is some sample code.

! /usr/bin/env python

import fmcapi

def main(): host = "ips-reg-mgmt" username = "admin" password = "admin123" autodeploy = False file_logging = "accessrules.log"

with fmcapi.FMC(
    host=host,
    username=username,
    password=password,
    autodeploy=autodeploy,
    file_logging=file_logging
) as fmc1:

    apiobj = fmcapi.AccessRules(fmc=fmc1, acp_name="Internet Edge")
    apidata = apiobj.get()
    apidata_items = apidata["items"]
    print(f"The items are: {apidata_items}")

if name == "main": main()

Here is the terminal output when running the code. Logging is enabled and set to INFO. Look for file "accessrules.log" for output. INFO:root:Requesting new tokens from https://ips-reg-mgmt/api/fmc_platform/v1/auth/generatetoken. INFO:root:Building base to URLs. INFO:root:Populating vdbVersion, sruVersion, serverVersion, and geoVersion FMC instance variables. INFO:root:This FMC's version is 6.6.5.2 (build 14) INFO:root:GET success. Object with name: "Internet Edge" and id: "70E422E5-E2BC-0ed3-0000-236223289070" fetched from FMC.


APIOBJ <fmcapi.api_objects.policy_services.accessrules.AccessRules object at 0x7fabc4a84be0>


INFO:root:Auto deploy changes set to False. Use the Deploy button in FMC to push changes to FTDs. Traceback (most recent call last): File "/home/bwollmann/.venv/ans215/lib/python3.10/site-packages/urllib3/connectionpool.py", line 536, in _make_request response = conn.getresponse() File "/home/bwollmann/.venv/ans215/lib/python3.10/site-packages/urllib3/connection.py", line 461, in getresponse httplib_response = super().getresponse() File "/usr/lib/python3.10/http/client.py", line 1375, in getresponse response.begin() File "/usr/lib/python3.10/http/client.py", line 318, in begin version, status, reason = self._read_status() File "/usr/lib/python3.10/http/client.py", line 279, in _read_status line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1") File "/usr/lib/python3.10/socket.py", line 705, in readinto return self._sock.recv_into(b) File "/usr/lib/python3.10/ssl.py", line 1303, in recv_into return self.read(nbytes, buffer) File "/usr/lib/python3.10/ssl.py", line 1159, in read return self._sslobj.read(len, buffer) TimeoutError: The read operation timed out

The above exception was the direct cause of the following exception:

Traceback (most recent call last): File "/home/bwollmann/.venv/ans215/lib/python3.10/site-packages/requests/adapters.py", line 486, in send resp = conn.urlopen( File "/home/bwollmann/.venv/ans215/lib/python3.10/site-packages/urllib3/connectionpool.py", line 844, in urlopen retries = retries.increment( File "/home/bwollmann/.venv/ans215/lib/python3.10/site-packages/urllib3/util/retry.py", line 470, in increment raise reraise(type(error), error, _stacktrace) File "/home/bwollmann/.venv/ans215/lib/python3.10/site-packages/urllib3/util/util.py", line 39, in reraise raise value File "/home/bwollmann/.venv/ans215/lib/python3.10/site-packages/urllib3/connectionpool.py", line 790, in urlopen response = self._make_request( File "/home/bwollmann/.venv/ans215/lib/python3.10/site-packages/urllib3/connectionpool.py", line 538, in _make_request self._raise_timeout(err=e, url=url, timeout_value=read_timeout) File "/home/bwollmann/.venv/ans215/lib/python3.10/site-packages/urllib3/connectionpool.py", line 370, in _raise_timeout raise ReadTimeoutError( urllib3.exceptions.ReadTimeoutError: HTTPSConnectionPool(host='ips-reg-mgmt', port=443): Read timed out. (read timeout=5)

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/home/bwollmann/repos/iac/python/fmc/accessrules.py", line 41, in main() File "/home/bwollmann/repos/iac/python/fmc/accessrules.py", line 26, in main apidata = apiobj.get() File "/home/bwollmann/.venv/ans215/lib/python3.10/site-packages/fmcapi/api_objects/apiclasstemplate.py", line 263, in get response = self.fmc.send_to_api(method="get", url=url) File "/home/bwollmann/.venv/ans215/lib/python3.10/site-packages/fmcapi/fmc.py", line 215, in send_to_api response = requests.get( File "/home/bwollmann/.venv/ans215/lib/python3.10/site-packages/requests/api.py", line 73, in get return request("get", url, params=params, kwargs) File "/home/bwollmann/.venv/ans215/lib/python3.10/site-packages/requests/api.py", line 59, in request return session.request(method=method, url=url, kwargs) File "/home/bwollmann/.venv/ans215/lib/python3.10/site-packages/requests/sessions.py", line 589, in request resp = self.send(prep, send_kwargs) File "/home/bwollmann/.venv/ans215/lib/python3.10/site-packages/requests/sessions.py", line 703, in send r = adapter.send(request, kwargs) File "/home/bwollmann/.venv/ans215/lib/python3.10/site-packages/requests/adapters.py", line 532, in send raise ReadTimeout(e, request=request) requests.exceptions.ReadTimeout: HTTPSConnectionPool(host='ips-reg-mgmt', port=443): Read timed out. (read timeout=5)

Expected behavior I expect the print statement to output the JSON payload. However, the program errors out before reaching the print statement.

Screenshots n/a

Python environment aiofiles==23.2.1 aiohttp==3.8.5 aiohttp-swagger==1.0.16 aiosignal==1.3.1 ansible==8.4.0 ansible-compat==4.1.10 ansible-core==2.15.4 ansible-lint==6.20.3 ansible-pylibssh==1.1.0 arrow==1.3.0 async-lru==2.0.4 async-timeout==4.0.3 attrs==23.1.0 backports.ssl==0.0.9 backports.ssl-match-hostname==3.7.0.1 bcrypt==4.0.1 binaryornot==0.4.4 black==23.9.1 bracex==2.4 certifi==2023.7.22 cffi==1.16.0 chardet==4.0.0 charset-normalizer==3.3.0 click==8.1.7 cookiecutter==2.4.0 cryptography==41.0.4 DateTime==5.4 dict2xml==1.7.3 dill==0.3.7 distro==1.8.0 f5-icontrol-rest==1.3.13 filelock==3.12.4 fmcapi==20231211.0 frozenlist==1.4.0 genie==23.9 genie.libs.clean==23.9 genie.libs.conf==23.9 genie.libs.filetransferutils==23.9 genie.libs.health==23.9 genie.libs.ops==23.9 genie.libs.parser==23.9 genie.libs.robot==23.9 genie.libs.sdk==23.9 genie.telemetry==23.9 genie.trafficgen==23.9 gitdb==4.0.10 GitPython==3.1.37 grpcio==1.59.0 idna==3.4 ipaddress==1.0.23 IxNetwork==9.30.2212.7 ixnetwork-restpy==1.1.10 Jinja2==3.1.2 jmespath==1.0.1 jsonpickle==3.0.2 jsonschema==4.19.1 jsonschema-specifications==2023.7.1 junit-xml==1.9 lxml==4.9.3 markdown-it-py==3.0.0 MarkupSafe==2.1.3 mdurl==0.1.2 multidict==6.0.4 mypy-extensions==1.0.0 ncclient==0.6.13 netaddr==0.9.0 numpy==1.26.3 packaging==23.2 pandas==2.1.4 paramiko==3.3.1 pathlib2==2.3.7.post1 pathspec==0.11.2 platformdirs==3.11.0 ply==3.11 prettytable==3.9.0 protobuf==4.24.4 psutil==5.9.5 pyasn1==0.4.8 pyats==23.9 pyats.aereport==23.9 pyats.aetest==23.9 pyats.async==23.9 pyats.connections==23.9 pyats.contrib==23.9 pyats.datastructures==23.9 pyats.easypy==23.9 pyats.kleenex==23.9 pyats.log==23.9 pyats.reporter==23.9 pyats.results==23.9 pyats.robot==23.9 pyats.tcl==23.9 pyats.topology==23.9 pyats.utils==23.9 pycparser==2.21 pyftpdlib==1.5.8 Pygments==2.16.1 PyNaCl==1.5.0 pyOpenSSL==23.2.0 pysmi-lextudio==1.1.13 pysnmp-lextudio==5.0.29 pysnmpcrypto==0.0.4 python-dateutil==2.8.2 python-engineio==3.14.2 python-slugify==8.0.1 python-socketio==4.6.1 pytz==2023.3.post1 PyYAML==6.0.1 referencing==0.30.2 requests==2.31.0 requests-toolbelt==1.0.0 resolvelib==1.0.1 rest.connector==23.9 rich==13.6.0 robotframework==6.1.1 rpds-py==0.10.4 ruamel.yaml==0.17.35 ruamel.yaml.clib==0.2.8 six==1.16.0 smmap==5.0.1 subprocess-tee==0.4.1 text-unidecode==1.3 tftpy==0.8.0 tomli==2.0.1 tqdm==4.66.1 types-python-dateutil==2.8.19.14 typing_extensions==4.8.0 tzdata==2023.4 unicon==23.9 unicon.plugins==23.9 urllib3==2.0.6 wcmatch==8.5 wcwidth==0.2.8 websocket-client==1.6.3 xlrd==1.2.0 XlsxWriter==3.1.6 xlwt==1.3.0 xmltodict==0.13.0 yamllint==1.32.0 yang.connector==23.9 yarl==1.9.2 zope.interface==6.1

Additional context I don't know if I'm using the API wrong or if there is a bug. My calls to other API endpoints work flawlessly.

marksull commented 9 months ago

You are seeing a requests.exceptions.ReadTimeout: HTTPSConnectionPool(host='ips-reg-mgmt', port=443): Read timed out. (read timeout=5). Try increasing the timeout from the default of 5, to something larger, for example:

with fmcapi.FMC(
    host=host,
    username=username,
    password=password,
    autodeploy=autodeploy,
    file_logging=file_logging,
    timeout=60
) as fmc1:
wollmannbruno commented 9 months ago

Ugh. This was precisely the issue. I poured over the code in accessrules.py before creating this issue, but completely missed the timeout setting in fmc.py.

Thanks for your response.