proxy.py
proxy.py copied to clipboard
[Plugin] Unable to load using absolute path
Describe the bug This states that one can load a plugin simply by using the absolute path for the plugin but it's not working for me
python -m proxy --log-level d --ca-key-file ca-key.pem --ca-cert-file ca-cert.pem --ca-signing-key-file ca-signing-key.pem --plugins /home/mohammad/repos/plugintest/proxyPlugin.proxyPlugin
Traceback (most recent call last):
File "/usr/lib/python3.9/runpy.py", line 197, in _run_module_as_main
return _run_code(code, main_globals, None,
File "/usr/lib/python3.9/runpy.py", line 87, in _run_code
exec(code, run_globals)
File "/home/mohammad/repos/proxy.py/proxy/__main__.py", line 14, in <module>
entry_point()
File "/home/mohammad/repos/proxy.py/proxy/proxy.py", line 176, in entry_point
main(input_args=sys.argv[1:])
File "/home/mohammad/repos/proxy.py/proxy/proxy.py", line 155, in main
with Proxy(input_args=input_args, **opts):
File "/home/mohammad/repos/proxy.py/proxy/proxy.py", line 105, in __init__
self.flags = FlagParser.initialize(input_args, **opts)
File "/home/mohammad/repos/proxy.py/proxy/common/flag.py", line 100, in initialize
Plugins.discover(input_args)
File "/home/mohammad/repos/proxy.py/proxy/common/plugins.py", line 38, in discover
Plugins.importer(bytes_(part))
File "/home/mohammad/repos/proxy.py/proxy/common/plugins.py", line 75, in importer
importlib.import_module(
File "/usr/lib/python3.9/importlib/__init__.py", line 122, in import_module
raise TypeError(msg.format(name))
TypeError: the 'package' argument is required to perform a relative import for '.home.mohammad.repos.plugintest.proxyPlugin'
To Reproduce
Steps to reproduce the behavior:
1- create a simple plugin in a directory outside proxy.py
tree for me i created a directory at /home/mohammad/repos/plugintest/
that contains a file named proxyPlugin.py
the file contains a plugin class named proxyPlugin
2. Run proxy.py
as python -m proxy --log-level d --ca-key-file ca-key.pem --ca-cert-file ca-cert.pem --ca-signing-key-file ca-signing-key.pem --plugins /home/mohammad/repos/plugintest/proxyPlugin.proxyPlugin
3- The following exception is raised TypeError: the 'package' argument is required to perform a relative import for '.home.mohammad.repos.plugintest.proxyPlugin'
Expected behavior
According to the README.md
file using the absolute path for the plugin should work just fine
Version information
-
OS: Manjaro linux
-
Device: Desktop pc
-
proxy.py version: git version
@moham96 IIRC, relative imports are not allowed within plugins. I might have to double check on this, but can you try to make your imports absolute and give it a try. If necessary add your plugin module as PYTHONPATH
too. Let me know.
You can also try:
PYTHONPATH=/home/mohammad/repos/plugintest proxy --plugins proxyPlugin.proxyPlugin
Ref: https://github.com/abhinavsingh/proxy.py#unable-to-load-plugins
You can also try:
PYTHONPATH=/home/mohammad/repos/plugintest proxy --plugins proxyPlugin.proxyPlugin
Ref: https://github.com/abhinavsingh/proxy.py#unable-to-load-plugins
using PYTHONPATH
works fine, but the entry in the README file suggest that it is possible to use the absolute path without setting the PYTHONPATH
variable
using
PYTHONPATH
works fine, but the entry in the README file suggest that it is possible to use the absolute path without setting thePYTHONPATH
variable
Correct. In my tests it worked while documenting. But IIRC, I was using absolute imports in my external plugin. Probably, I we must update the README with relevant context. If you wish, please send out a PR.
TypeError: the 'package' argument is required to perform a relative import for '.home.mohammad.repos.plugintest.proxyPlugin'
Can double confirm, absolute path currently doesn't work as advertised. I think code got broken at some point, because this used to work. Let's keep this open until fixed. Thank you again for reporting it.