vulnersCom / api

Vulners Python API wrapper
GNU General Public License v3.0
356 stars 60 forks source link

AttributeError: module '__main__' has no attribute '__file__' #9

Closed changebias closed 5 years ago

changebias commented 5 years ago

Hello.

I have Ubuntu 18.04.1 LTS & Python 3.6.7. I guess this is a bug.

pip3 install -U vulners
Collecting vulners
  Using cached https://files.pythonhosted.org/packages/43/b3/c09774d2725eb93c98f8055591b4d90b469495886e9573ae26a68db0e790/vulners-1.4.0-py3-none-any.whl
Collecting six (from vulners)
  Using cached https://files.pythonhosted.org/packages/73/fb/00a976f728d0d1fecfe898238ce23f502a721c0ac0ecfedb80e0d88c64e9/six-1.12.0-py2.py3-none-any.whl
Collecting requests (from vulners)
  Using cached https://files.pythonhosted.org/packages/7d/e3/20f3d364d6c8e5d2353c72a67778eb189176f08e873c9900e10c0287b84b/requests-2.21.0-py2.py3-none-any.whl
Collecting idna<2.9,>=2.5 (from requests->vulners)
  Using cached https://files.pythonhosted.org/packages/14/2c/cd551d81dbe15200be1cf41cd03869a46fe7226e7450af7a6545bfc474c9/idna-2.8-py2.py3-none-any.whl
Collecting chardet<3.1.0,>=3.0.2 (from requests->vulners)
  Using cached https://files.pythonhosted.org/packages/bc/a9/01ffebfb562e4274b6487b4bb1ddec7ca55ec7510b22e4c51f14098443b8/chardet-3.0.4-py2.py3-none-any.whl
Collecting certifi>=2017.4.17 (from requests->vulners)
  Using cached https://files.pythonhosted.org/packages/9f/e0/accfc1b56b57e9750eba272e24c4dddeac86852c2bebd1236674d7887e8a/certifi-2018.11.29-py2.py3-none-any.whl
Collecting urllib3<1.25,>=1.21.1 (from requests->vulners)
  Using cached https://files.pythonhosted.org/packages/62/00/ee1d7de624db8ba7090d1226aebefab96a2c71cd5cfa7629d6ad3f61b79e/urllib3-1.24.1-py2.py3-none-any.whl
Installing collected packages: six, idna, chardet, certifi, urllib3, requests, vulners
Successfully installed certifi-2018.11.29 chardet-3.0.4 idna-2.8 requests-2.21.0 six-1.12.0 urllib3-1.24.1 vulners-1.4.0

~/Documents/OKRs/okrs on  master! ⌚ 0:57:20
$ ipython                
Python 3.6.7 (default, Oct 22 2018, 11:32:17) 
Type 'copyright', 'credits' or 'license' for more information
IPython 7.2.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]: import vulners                                                          

In [2]: api = 'api key'                                                         

In [3]: vulners_api = vulners.Vulners(api_key=api)                              
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-3-cc52c8878696> in <module>
----> 1 vulners_api = vulners.Vulners(api_key=api)

~/.local/lib/python3.6/site-packages/vulners/api.py in __init__(self, api_key, proxies, persistent)
     66         self.__opener = requests.session()
     67         if persistent:
---> 68             self.__opener.cookies = PersistentCookieJar()
     69         # Setup pool size and Keep Alive
     70         adapter = requests.adapters.HTTPAdapter(

~/.local/lib/python3.6/site-packages/vulners/common/cookiejar.py in __init__(self, file_path, *args, **kwargs)
     44         super(PersistentCookieJar, self).__init__(*args, **kwargs)
     45 
---> 46         self.__file_path = file_path or os.path.join(self.__get_temp_dir(), self.__get_module_name())
     47 
     48         # Try to recover from file if it does exist

~/.local/lib/python3.6/site-packages/vulners/common/cookiejar.py in __get_module_name(self)
     66         :return: string, Python module name
     67         """
---> 68         full_module_file_path = six.text_type(sys.modules['__main__'].__file__)
     69         path_hash = hashlib.sha1(full_module_file_path.encode('utf-8')).hexdigest()
     70         return "%s.cookiejar" % path_hash

AttributeError: module '__main__' has no attribute '__file__'

In [4]:       
changebias commented 5 years ago

The previous major version (1.3.0) works fine.

vulnersCom commented 5 years ago

Definitely yes. Will fix it asap.

vulnersCom commented 5 years ago

Fixed at 1.4.1

https://github.com/vulnersCom/api/commit/8fcd843879fbfe32b22ff08a3660b2c5c3d461e5

Is it ok now?

changebias commented 5 years ago

Thanks for the speed, everything works fine with 1.4.1.