Oct-29-2022, 05:20 PM
Hi, I am new to the forums and this is my first post.
I am new to python, more familiar with bash scripting, however I am trying to write a python script/program that will update a work repository for storing information on IP network information.
i.e. Network name, IPv4 range, IPv4 CIDR, IPv6 range, IPv6 CIDR, etc. etc. There are quite a lot of fields. Each network record is stored in a dictionary.
e.g (Values removed)
{'name': 'xxxx', 'ipv4_start': 'xxxx', 'ipv4_cidr': xx, 'ipv4_address_domain_id': xxxx, 'INFO-ipv4_address_domain_name': 'xxxx', 'ipv4_address_domain_range_id': xxxx, 'INFO-ipv4_address_domain_range_name': 'xxxxx', 'ipv4_allocation_template_id': xxxx, 'dhcp_relay_id': '', 'ipv6_start': 'xxxx::', 'ipv6_cidr': 64.0, 'ipv6_address_domain_id': xxxx, 'INFO-ipv6_address_domain_id': 'xxxxx', 'ipv6_address_domain_range_id': xxxxx, 'INFO-ipv6_address_domain_range_name': 'xxxxxx::/49', 'ipv6_allocation_template_id': xxxx, 'dhcpv6_relay_id': '', 'l2_vni_value': '', 'INFO-l2_vni_name': '', 'l2_domain_id': '', 'INFO-l2_domain_name': '', 'dns_domain_id': '', 'INFO-dns_domain_name': '', 'is_infoblox_synced': xxxx, 'is_private': xxxx, 'tenant_id': xxxx, 'INFO-tenant_name': 'xxxx', 'partition_id': xxxx, 'INFO-partition_name': 'xxxx', 'provider_id': xxxx, 'INFO-provider_name': 'xxxxx', 'consumer_id': xxxx, 'INFO-resp_consumer_name': 'xxxx', 'other_consumers': '', 'INFO-other_consumer_names': '', 'vlan_tag': xxxx, 'INFO-vlan_name': '', 'description': '', 'hashtags': '', 'discovery_organization_id': '', 'INFO-discovery_organization_name': 'xxxx', 'discovery_credential_id': '', 'INFO-discovery_credential_name': 'xxxx', 'discovery_scanner_id': '', 'INFO-discovery_scanner_name': 'xxxx', 'discovery_exclude_justification': 'xxxx', 'INFO-Comments-Notes': ''}
Not every key will have a value. Some networks might be IPv4 only for instance, so no IPv6 values. I used the "df.fillna" method to change the pandas "nan" values to be an empty string with " ".
I am testing a single dictionary entry against a test repository but I am getting an error "'str' object is not callable".
My code (using Jupyter Notebook)
I am hoping that someone here may be able to point me in the right direction to resolve this issue.
Any assistance provide would be very much appreciated.
Cheers
I am new to python, more familiar with bash scripting, however I am trying to write a python script/program that will update a work repository for storing information on IP network information.
i.e. Network name, IPv4 range, IPv4 CIDR, IPv6 range, IPv6 CIDR, etc. etc. There are quite a lot of fields. Each network record is stored in a dictionary.
e.g (Values removed)
{'name': 'xxxx', 'ipv4_start': 'xxxx', 'ipv4_cidr': xx, 'ipv4_address_domain_id': xxxx, 'INFO-ipv4_address_domain_name': 'xxxx', 'ipv4_address_domain_range_id': xxxx, 'INFO-ipv4_address_domain_range_name': 'xxxxx', 'ipv4_allocation_template_id': xxxx, 'dhcp_relay_id': '', 'ipv6_start': 'xxxx::', 'ipv6_cidr': 64.0, 'ipv6_address_domain_id': xxxx, 'INFO-ipv6_address_domain_id': 'xxxxx', 'ipv6_address_domain_range_id': xxxxx, 'INFO-ipv6_address_domain_range_name': 'xxxxxx::/49', 'ipv6_allocation_template_id': xxxx, 'dhcpv6_relay_id': '', 'l2_vni_value': '', 'INFO-l2_vni_name': '', 'l2_domain_id': '', 'INFO-l2_domain_name': '', 'dns_domain_id': '', 'INFO-dns_domain_name': '', 'is_infoblox_synced': xxxx, 'is_private': xxxx, 'tenant_id': xxxx, 'INFO-tenant_name': 'xxxx', 'partition_id': xxxx, 'INFO-partition_name': 'xxxx', 'provider_id': xxxx, 'INFO-provider_name': 'xxxxx', 'consumer_id': xxxx, 'INFO-resp_consumer_name': 'xxxx', 'other_consumers': '', 'INFO-other_consumer_names': '', 'vlan_tag': xxxx, 'INFO-vlan_name': '', 'description': '', 'hashtags': '', 'discovery_organization_id': '', 'INFO-discovery_organization_name': 'xxxx', 'discovery_credential_id': '', 'INFO-discovery_credential_name': 'xxxx', 'discovery_scanner_id': '', 'INFO-discovery_scanner_name': 'xxxx', 'discovery_exclude_justification': 'xxxx', 'INFO-Comments-Notes': ''}
Not every key will have a value. Some networks might be IPv4 only for instance, so no IPv6 values. I used the "df.fillna" method to change the pandas "nan" values to be an empty string with " ".
I am testing a single dictionary entry against a test repository but I am getting an error "'str' object is not callable".
My code (using Jupyter Notebook)
import requests import json token = '12345678987654321' network = {'name': 'xxxx', 'ipv4_start': 'xxxx', 'ipv4_cidr': xx, 'ipv4_address_domain_id': xxxx, 'INFO-ipv4_address_domain_name': 'xxxx', 'ipv4_address_domain_range_id': xxxx, 'INFO-ipv4_address_domain_range_name': 'xxxxx', 'ipv4_allocation_template_id': xxxx, 'dhcp_relay_id': '', 'ipv6_start': 'xxxx::', 'ipv6_cidr': 64.0, 'ipv6_address_domain_id': xxxx, 'INFO-ipv6_address_domain_id': 'xxxxx', 'ipv6_address_domain_range_id': xxxxx, 'INFO-ipv6_address_domain_range_name': 'xxxxxx::/49', 'ipv6_allocation_template_id': xxxx, 'dhcpv6_relay_id': '', 'l2_vni_value': '', 'INFO-l2_vni_name': '', 'l2_domain_id': '', 'INFO-l2_domain_name': '', 'dns_domain_id': '', 'INFO-dns_domain_name': '', 'is_infoblox_synced': xxxx, 'is_private': xxxx, 'tenant_id': xxxx, 'INFO-tenant_name': 'xxxx', 'partition_id': xxxx, 'INFO-partition_name': 'xxxx', 'provider_id': xxxx, 'INFO-provider_name': 'xxxxx', 'consumer_id': xxxx, 'INFO-resp_consumer_name': 'xxxx', 'other_consumers': '', 'INFO-other_consumer_names': '', 'vlan_tag': xxxx, 'INFO-vlan_name': '', 'description': '', 'hashtags': '', 'discovery_organization_id': '', 'INFO-discovery_organization_name': 'xxxx', 'discovery_credential_id': '', 'INFO-discovery_credential_name': 'xxxx', 'discovery_scanner_id': '', 'INFO-discovery_scanner_name': 'xxxx', 'discovery_exclude_justification': 'xxxx', 'INFO-Comments-Notes': ''} response = requests.post('https://<url for repository>', auth=(token), data=json.dumps(network)) print(response)The trace back I receive is
TypeError Traceback (most recent call last) ~\AppData\Local\Temp\ipykernel_27884\2338555186.py in <module> 6 network = {'name': 'xxxx', 'ipv4_start': 'xxxx', 'ipv4_cidr': xx, 'ipv4_address_domain_id': xxxx, 'INFO-ipv4_address_domain_name': 'xxxx', 'ipv4_address_domain_range_id': xxxx, 'INFO-ipv4_address_domain_range_name': 'xxxxx', 'ipv4_allocation_template_id': xxxx, 'dhcp_relay_id': '', 'ipv6_start': 'xxxx::', 'ipv6_cidr': 64.0, 'ipv6_address_domain_id': xxxx, 'INFO-ipv6_address_domain_id': 'xxxxx', 'ipv6_address_domain_range_id': xxxxx, 'INFO-ipv6_address_domain_range_name': 'xxxxxx::/49', 'ipv6_allocation_template_id': xxxx, 'dhcpv6_relay_id': '', 'l2_vni_value': '', 'INFO-l2_vni_name': '', 'l2_domain_id': '', 'INFO-l2_domain_name': '', 'dns_domain_id': '', 'INFO-dns_domain_name': '', 'is_infoblox_synced': xxxx, 'is_private': xxxx, 'tenant_id': xxxx, 'INFO-tenant_name': 'xxxx', 'partition_id': xxxx, 'INFO-partition_name': 'xxxx', 'provider_id': xxxx, 'INFO-provider_name': 'xxxxx', 'consumer_id': xxxx, 'INFO-resp_consumer_name': 'xxxx', 'other_consumers': '', 'INFO-other_consumer_names': '', 'vlan_tag': xxxx, 'INFO-vlan_name': '', 'description': '', 'hashtags': '', 'discovery_organization_id': '', 'INFO-discovery_organization_name': 'xxxx', 'discovery_credential_id': '', 'INFO-discovery_credential_name': 'xxxx', 'discovery_scanner_id': '', 'INFO-discovery_scanner_name': 'xxxx', 'discovery_exclude_justification': 'xxxx', 'INFO-Comments-Notes': ''} 7 ----> 8 response = requests.post('https://<url for respoitory>', auth=(token), data=json.dumps(network)) ~\Anaconda3\lib\site-packages\requests\api.py in post(url, data, json, **kwargs) 113 """ 114 --> 115 return request("post", url, data=data, json=json, **kwargs) 116 117 ~\Anaconda3\lib\site-packages\requests\api.py in request(method, url, **kwargs) 57 # cases, and look like a memory leak in others. 58 with sessions.Session() as session: ---> 59 return session.request(method=method, url=url, **kwargs) 60 61 ~\Anaconda3\lib\site-packages\requests\sessions.py in request(self, method, url, params, data, headers, cookies, files, auth, timeout, allow_redirects, proxies, hooks, stream, verify, cert, json) 571 hooks=hooks, 572 ) --> 573 prep = self.prepare_request(req) 574 575 proxies = proxies or {} ~\Anaconda3\lib\site-packages\requests\sessions.py in prepare_request(self, request) 482 483 p = PreparedRequest() --> 484 p.prepare( 485 method=request.method.upper(), 486 url=request.url, ~\Anaconda3\lib\site-packages\requests\models.py in prepare(self, method, url, headers, files, data, params, auth, cookies, hooks, json) 370 self.prepare_cookies(cookies) 371 self.prepare_body(data, files, json) --> 372 self.prepare_auth(auth, url) 373 374 # Note that prepare_auth must be last to enable authentication schemes ~\Anaconda3\lib\site-packages\requests\models.py in prepare_auth(self, auth, url) 601 602 # Allow auth to make its changes. --> 603 r = auth(self) 604 605 # Update self to reflect the auth changes. TypeError: 'str' object is not callableI have looked on google, stackoverflow, youtube but I have not found any resolutions to this issue. If I run this same code into "https://httpbin.org/post" I receive a "200" response

I am hoping that someone here may be able to point me in the right direction to resolve this issue.
Any assistance provide would be very much appreciated.
Cheers