rapid7 / nexpose-client-python

DEPRECATED : Rapid7 Nexpose API client library written in Python
https://www.rapid7.com/
BSD 3-Clause "New" or "Revised" License
25 stars 20 forks source link

module 'nexpose' has no attribute 'NexposeSession' in version 0.1.3 #23

Closed derpadoo closed 7 years ago

derpadoo commented 7 years ago

Have not been able to get the version 0.1.3 working.

Expected Behavior

Establish session with Nexpose console.

Current Behavior

It's happening in both a 3.5 virtualenv and a system-wide install of both Python2 'pip install nexpose' and Python3 'pip3 install nexpose'. Reverted to the 0.1.2 tag and not having any issues with the Python2 working. Another observation is that after importing the nexpose module in ipython, tab completion of nexpose. does not provide any hints of the module's attributes. That may be an ipython thing, but I don't have the issue with other libraries like requests. The run_demo.py code that calls make_dlnexpose_importable() seems redundant and unnecessary.

Possible Solution

Version 0.1.3 broke something.

Steps to Reproduce (for bugs)

To set up the environment

virtualenv -p /usr/bin/python3.5 .venv
source .venv/bin/activate
pip install nexpose
pip install ipython

Python code that reproduces the issue:

Copy/pasted from run_demo.py

# ipython
Python 3.5.4 (default, Aug 12 2017, 14:08:14) 
Type 'copyright', 'credits' or 'license' for more information
IPython 6.1.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]: from __future__ import (absolute_import, division, print_function,
   ...:                         unicode_literals)
   ...: 
   ...: from builtins import map
   ...: from builtins import input
   ...: from builtins import range
   ...: from fix_path import make_dlnexpose_importable
   ...: from time import sleep
   ...: from io import BytesIO
   ...: from zipfile import ZipFile
   ...: import sslfix
   ...: import nexpose as nexpose
   ...: from future import standard_library
   ...: standard_library.install_aliases()
   ...: make_dlnexpose_importable()
   ...: 

In [2]: def GetNexposeLoginSettings():
   ...:     """
   ...:     Returns a list with following information: hostname_or_ip, port, username, password.
   ...:     An exception is raised if "demo.cfg" is not found or contains invalid/no data.
   ...:     """
   ...:     try:
   ...:         with open("demo.cfg") as config_file:
   ...:             for line in config_file.readlines():
   ...:                 if not line.strip().startswith('#'):
   ...:                     data = line.split()
   ...:                     if len(data) != 4:
   ...:                         raise ValueError("demo.cfg contains invalid data")
   ...:                     return data
   ...:         raise ValueError("demo.cfg contains no data")
   ...:     except:
   ...:         raise Exception("demo.cfg could not be found, please refer to demo.cfg.default")
   ...: 
   ...: 
   ...: def InitializeGlobalSession():
   ...:     """Returns a tuple with following information: (hostname_or_ip, port, username, password)"""
   ...:     global session
   ...: 
   ...:     login_info = GetNexposeLoginSettings()
   ...:     session = nexpose.NexposeSession.Create(*login_info)
   ...:     wait_for_status(nexpose.NexposeStatus.NORMAL_MODE, "Waiting for the console to be ready:")
   ...:     print("The Security Console is ready...")
   ...:     session.Open()
   ...:     

In [3]: InitializeGlobalSession()
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-3-858a2516dfcf> in <module>()
----> 1 InitializeGlobalSession()

<ipython-input-2-3a662e0ec35d> in InitializeGlobalSession()
     22 
     23     login_info = GetNexposeLoginSettings()
---> 24     session = nexpose.NexposeSession.Create(*login_info)
     25     wait_for_status(nexpose.NexposeStatus.NORMAL_MODE, "Waiting for the console to be ready:")
     26     print("The Security Console is ready...")

AttributeError: module 'nexpose' has no attribute 'NexposeSession'

Context

nexpose module isn't working.

Your Environment

gschneider-r7 commented 7 years ago

I may have been too hasty to get the Python 3 support out. 😞

Regarding the make_dlnexpose_importable() thing, this is leftover from before I re-arranged the package layout. I think there is still work to be done to properly handle imports across the whole library, as it's not straightforward compared to some other libraries (like Requests as you pointed out). Unfortunately I'm not an expert on packaging Python libraries so any tips on that would be appreciated.

I will take a look at this later today. Sorry about the broken release! Wonder if it's easy enough to revoke it from pypi...

derpadoo commented 7 years ago

No worries, just glad this repo has some momentum and you respond to tickets. I've never dealt with building Python packages before either, but I can take a look and see if anything may help.

gschneider-r7 commented 7 years ago

I released version 0.1.4 which reverts the changes, and should be available on pypi now.

I need to spend more time working out my changes that seem to fix the issue otherwise, but broke tests (due to import issues). Seems like a good time to really clean up the import mess that was caused by this library not originally being package-ready, and my newbie attempt at packaging it up.

gschneider-r7 commented 7 years ago

I've started a branch fix_imports_py2_py3 if anyone wants to keep an eye on it or help out (target PRs to that branch instead of master in this case).