InsightVM Python from GitHub

We’re trying to utilize the scripting features from the InsightVM GitHub repo. We’re running into errors and I was curious if anyone was able to work around these or if they reached out to Rapid7 for assistance.

I’m using the sample “assets.py” file in the repo.
Rapid7 VM Console Python Stuff

Traceback (most recent call last):
  File "c:/Users/uid/Documents/Scripts/Rapid7/poam.py", line 38, in <module>
    assets = asset_api.get_assets()
  File "C:\Users\uid\AppData\Local\Programs\Python\Python38-32\lib\site-packages\rapid7vmconsole\api\asset_api.py", line 2081, in get_assets
    (data) = self.get_assets_with_http_info(**kwargs)  # noqa: E501
  File "C:\Users\uid\AppData\Local\Programs\Python\Python38-32\lib\site-packages\rapid7vmconsole\api\asset_api.py", line 2148, in get_assets_with_http_info
    return self.api_client.call_api(
  File "C:\Users\uid\AppData\Local\Programs\Python\Python38-32\lib\site-packages\rapid7vmconsole\api_client.py", line 315, in call_api
    return self.__call_api(resource_path, method,
  File "C:\Users\uid\AppData\Local\Programs\Python\Python38-32\lib\site-packages\rapid7vmconsole\api_client.py", line 159, in __call_api
    return_data = self.deserialize(response_data, response_type)
  File "C:\Users\uid\AppData\Local\Programs\Python\Python38-32\lib\site-packages\rapid7vmconsole\api_client.py", line 231, in deserialize
    return self.__deserialize(data, response_type)
  File "C:\Users\uid\AppData\Local\Programs\Python\Python38-32\lib\site-packages\rapid7vmconsole\api_client.py", line 270, in __deserialize
    return self.__deserialize_model(data, klass)
  File "C:\Users\uid\AppData\Local\Programs\Python\Python38-32\lib\site-packages\rapid7vmconsole\api_client.py", line 611, in __deserialize_model
    kwargs[attr] = self.__deserialize(value, attr_type)
  File "C:\Users\uid\AppData\Local\Programs\Python\Python38-32\lib\site-packages\rapid7vmconsole\api_client.py", line 247, in __deserialize
    return [self.__deserialize(sub_data, sub_kls)
  File "C:\Users\uid\AppData\Local\Programs\Python\Python38-32\lib\site-packages\rapid7vmconsole\api_client.py", line 247, in <listcomp>
    return [self.__deserialize(sub_data, sub_kls)
  File "C:\Users\uid\AppData\Local\Programs\Python\Python38-32\lib\site-packages\rapid7vmconsole\api_client.py", line 270, in __deserialize
    return self.__deserialize_model(data, klass)
  File "C:\Users\uid\AppData\Local\Programs\Python\Python38-32\lib\site-packages\rapid7vmconsole\api_client.py", line 611, in __deserialize_model
    kwargs[attr] = self.__deserialize(value, attr_type)
  File "C:\Users\uid\AppData\Local\Programs\Python\Python38-32\lib\site-packages\rapid7vmconsole\api_client.py", line 247, in __deserialize
    return [self.__deserialize(sub_data, sub_kls)
  File "C:\Users\uid\AppData\Local\Programs\Python\Python38-32\lib\site-packages\rapid7vmconsole\api_client.py", line 247, in <listcomp>
    return [self.__deserialize(sub_data, sub_kls)
  File "C:\Users\uid\AppData\Local\Programs\Python\Python38-32\lib\site-packages\rapid7vmconsole\api_client.py", line 270, in __deserialize
    return self.__deserialize_model(data, klass)
  File "C:\Users\uid\AppData\Local\Programs\Python\Python38-32\lib\site-packages\rapid7vmconsole\api_client.py", line 611, in __deserialize_model
    kwargs[attr] = self.__deserialize(value, attr_type)
  File "C:\Users\uid\AppData\Local\Programs\Python\Python38-32\lib\site-packages\rapid7vmconsole\api_client.py", line 247, in __deserialize
    return [self.__deserialize(sub_data, sub_kls)
  File "C:\Users\uid\AppData\Local\Programs\Python\Python38-32\lib\site-packages\rapid7vmconsole\api_client.py", line 247, in <listcomp>
    return [self.__deserialize(sub_data, sub_kls)
  File "C:\Users\uid\AppData\Local\Programs\Python\Python38-32\lib\site-packages\rapid7vmconsole\api_client.py", line 270, in __deserialize
    return self.__deserialize_model(data, klass)
  File "C:\Users\uid\AppData\Local\Programs\Python\Python38-32\lib\site-packages\rapid7vmconsole\api_client.py", line 613, in __deserialize_model
    instance = klass(**kwargs)
  File "C:\Users\uid\AppData\Local\Programs\Python\Python38-32\lib\site-packages\rapid7vmconsole\models\configuration.py", line 48, in __init__
    self.name = name
  File "C:\Users\uid\AppData\Local\Programs\Python\Python38-32\lib\site-packages\rapid7vmconsole\models\configuration.py", line 73, in name
    raise ValueError("Invalid value for `name`, must not be `None`")  # noqa: E501
ValueError: Invalid value for `name`, must not be `None`

Just saw that I have the same behavior on my script. It might have something to do with the urllib2 that they use. I have to dig a bit deeper.

Traceback (most recent call last):
  File "/scannetadminhosts/bin/scanNetAdminHosts.py", line 796, in <module>
    main()
  File "/scannetadminhosts/bin/scanNetAdminHosts.py", line 776, in main
    scan_hosts()
  File "/scannetadminhosts/bin/scanNetAdminHosts.py", line 571, in scan_hosts
    prepare_insightvm_connection()
  File "/scannetadminhosts/bin/scanNetAdminHosts.py", line 367, in prepare_insightvm_connection
    api_response = api_instance.get_site_assets(SiteID, page=0, size=500).resources
  File "/usr/local/lib/python3.6/site-packages/rapid7vmconsole/api/site_api.py", line 2920, in get_site_assets
    (data) = self.get_site_assets_with_http_info(id, **kwargs)  # noqa: E501
  File "/usr/local/lib/python3.6/site-packages/rapid7vmconsole/api/site_api.py", line 3008, in get_site_assets_with_http_info
    collection_formats=collection_formats)
  File "/usr/local/lib/python3.6/site-packages/rapid7vmconsole/api_client.py", line 320, in call_api
    _preload_content, _request_timeout)
  File "/usr/local/lib/python3.6/site-packages/rapid7vmconsole/api_client.py", line 159, in __call_api
    return_data = self.deserialize(response_data, response_type)
  File "/usr/local/lib/python3.6/site-packages/rapid7vmconsole/api_client.py", line 231, in deserialize
    return self.__deserialize(data, response_type)
  File "/usr/local/lib/python3.6/site-packages/rapid7vmconsole/api_client.py", line 270, in __deserialize
    return self.__deserialize_model(data, klass)
  File "/usr/local/lib/python3.6/site-packages/rapid7vmconsole/api_client.py", line 611, in __deserialize_model
    kwargs[attr] = self.__deserialize(value, attr_type)
  File "/usr/local/lib/python3.6/site-packages/rapid7vmconsole/api_client.py", line 248, in __deserialize
    for sub_data in data]
  File "/usr/local/lib/python3.6/site-packages/rapid7vmconsole/api_client.py", line 248, in <listcomp>
    for sub_data in data]
  File "/usr/local/lib/python3.6/site-packages/rapid7vmconsole/api_client.py", line 270, in __deserialize
    return self.__deserialize_model(data, klass)
  File "/usr/local/lib/python3.6/site-packages/rapid7vmconsole/api_client.py", line 611, in __deserialize_model
    kwargs[attr] = self.__deserialize(value, attr_type)
  File "/usr/local/lib/python3.6/site-packages/rapid7vmconsole/api_client.py", line 248, in __deserialize
    for sub_data in data]
  File "/usr/local/lib/python3.6/site-packages/rapid7vmconsole/api_client.py", line 248, in <listcomp>
    for sub_data in data]
  File "/usr/local/lib/python3.6/site-packages/rapid7vmconsole/api_client.py", line 270, in __deserialize
    return self.__deserialize_model(data, klass)
  File "/usr/local/lib/python3.6/site-packages/rapid7vmconsole/api_client.py", line 611, in __deserialize_model
    kwargs[attr] = self.__deserialize(value, attr_type)
  File "/usr/local/lib/python3.6/site-packages/rapid7vmconsole/api_client.py", line 248, in __deserialize
    for sub_data in data]
  File "/usr/local/lib/python3.6/site-packages/rapid7vmconsole/api_client.py", line 248, in <listcomp>
    for sub_data in data]
  File "/usr/local/lib/python3.6/site-packages/rapid7vmconsole/api_client.py", line 270, in __deserialize
    return self.__deserialize_model(data, klass)
  File "/usr/local/lib/python3.6/site-packages/rapid7vmconsole/api_client.py", line 613, in __deserialize_model
    instance = klass(**kwargs)
  File "/usr/local/lib/python3.6/site-packages/rapid7vmconsole/models/configuration.py", line 48, in __init__
    self.name = name
  File "/usr/local/lib/python3.6/site-packages/rapid7vmconsole/models/configuration.py", line 73, in name
    raise ValueError("Invalid value for `name`, must not be `None`")  # noqa: E501
ValueError: Invalid value for `name`, must not be `None`

Or could it be that they only accept TLS 1.2 nowadays

Did you ever get to the bottom of this? I am also seeing the exact same problem

Yes, it’s was not the python lib. It was me forgetting some part

config = rapid7vmconsole.Configuration(name=‘Rapid7’)
config.username = login
config.password = password
config.host = url
config.verify_ssl = True
config.assert_hostname = False
config.proxy = None
config.ssl_ca_cert = ‘/etc/pki/tls/certs/ca-bundle.crt’
config.connection_pool_maxsize = None
config.cert_file = None
config.key_file = None
config.safe_chars_for_path_param = ‘’
auth = “%s:%s” % (config.username, config.password)
auth = base64.b64encode(auth.encode(‘ascii’)).decode()
client = rapid7vmconsole.ApiClient(configuration=config)
client.default_headers[‘Authorization’] = “Basic %s” % auth

I think it was the bold line above, I don’t remember exactly. I think I already wrote in another forum thread/post.

I have the bold line mentioned by fsfetea, but I still have the same issue.

Commenting out lines 72 and 73 from the configuration.py file fixes the issue.

"/usr/local/lib/python3.6/site-packages/rapid7vmconsole/models/configuration.py"


#        if name is None:
#            raise ValueError("Invalid value for `name`, must not be `None`")  # noqa: E501
2 Likes

I did not find a way to completely resolve the issue. I ended up building my own authentication mechanism in Python and building my own scripts without the use of the Rapid7 libraries.

1 Like

can you please share your authentication mechanism in Python?

1 Like

Thank you!!! - this took care of the issue when calling get_site_assets