Skip to content
This repository has been archived by the owner on Jan 10, 2023. It is now read-only.

Requests/Urllib3/six injection issue. #39

Open
joshpaulchan opened this issue Jun 12, 2019 · 1 comment
Open

Requests/Urllib3/six injection issue. #39

joshpaulchan opened this issue Jun 12, 2019 · 1 comment

Comments

@joshpaulchan
Copy link

Issue

When importing the requests library and calling new_object_graph, it fails complaining about Tkinter not being configured for the system.

The problem is that when calling new_object_graph, Pinject traverses the imported modules by default but for some reason it's error on importing Tkinter on python installations where Tkinter isn't supported (intentionally, i.e. python:3.7-alpine). I believe the import tree is application -> requests -> urllib3 -> six -> Tkinter. I'm not sure what the proper fix is here, but I wanted to report it in case it is an actual behavioral issue with Pinject.

Environment

Docker container: python3.7-alpine
Requests: 2.2.1
Pinject: v0.12

Reproduction

This should be enough to repro it:

# repro.py
import pinject

import requests

def main():
    graph = pinject.new_object_graph() # errors

if __name__ == "__main__":
    main()
(pinject-requests-tkinter) ~/w/pinject-requests-tkinter ❯❯❯ docker run --rm -it pinject-requests-tkinter                    master ✱ ◼
Python 3.7.3 (default, May 11 2019, 02:00:41)
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import repro
>>> repro.main()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/opt/app/repro.py", line 7, in main
    pinject.new_object_graph()
  File "/root/.local/share/virtualenvs/app-ueEJiAOq/lib/python3.7/site-packages/pinject/object_graph.py", line 100, in new_object_graph
    found_classes = finding.find_classes(modules, classes)
  File "/root/.local/share/virtualenvs/app-ueEJiAOq/lib/python3.7/site-packages/pinject/finding.py", line 32, in find_classes
    all_classes |= _find_classes_in_module(module)
  File "/root/.local/share/virtualenvs/app-ueEJiAOq/lib/python3.7/site-packages/pinject/finding.py", line 46, in _find_classes_in_module
    for member_name, member in inspect.getmembers(module):
  File "/usr/local/lib/python3.7/inspect.py", line 341, in getmembers
    value = getattr(object, key)
  File "/root/.local/share/virtualenvs/app-ueEJiAOq/lib/python3.7/site-packages/urllib3/packages/six.py", line 92, in __get__
    result = self._resolve()
  File "/root/.local/share/virtualenvs/app-ueEJiAOq/lib/python3.7/site-packages/urllib3/packages/six.py", line 115, in _resolve
    return _import_module(self.mod)
  File "/root/.local/share/virtualenvs/app-ueEJiAOq/lib/python3.7/site-packages/urllib3/packages/six.py", line 82, in _import_module
    __import__(name)
  File "/usr/local/lib/python3.7/tkinter/__init__.py", line 36, in <module>
    import _tkinter # If this fails your Python may not be configured for Tk
ImportError: Error loading shared library libtk8.6.so: No such file or directory (needed by /root/.local/share/virtualenvs/app-ueEJiAOq/lib/python3.7/lib-dynload/_tkinter.cpython-37m-x86_64-linux-gnu.so)
>>>

Also, apologies if this is the wrong place to put this! I figured it wasn't an issue with requests/urllib3/six (at least, I'd hope not) since they're so prevalent.

@joshpaulchan
Copy link
Author

joshpaulchan commented Jun 12, 2019

Oh, I should have looked more. This is exactly what is being described in issue #11 and #22

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant