Skip to content

bpython interpreter with pwn module  #612

Closed

Description

@B0y1n4o4

I don't know is this problem has been asked. Here is my problem.

>>> from pwn import *
Traceback (most recent call last):
  File "<input>", line 1, in <module>
    from pwn import *
  File "/usr/lib/python2.7/dist-packages/bpython/curtsiesfrontend/repl.py", line 257, in load_module
    module = pkgutil.ImpLoader.load_module(self, name)
  File "/usr/lib/python2.7/pkgutil.py", line 246, in load_module
    mod = imp.load_module(fullname, self.file, self.filename, self.etc)
  File "/usr/local/lib/python2.7/dist-packages/pwn/__init__.py", line 2, in <module>
    from .toplevel import *
  File "/usr/local/lib/python2.7/dist-packages/pwn/toplevel.py", line 2, in <module>
    from pwnlib                  import *
  File "/usr/lib/python2.7/dist-packages/bpython/curtsiesfrontend/repl.py", line 257, in load_module
    module = pkgutil.ImpLoader.load_module(self, name)
  File "/usr/lib/python2.7/pkgutil.py", line 246, in load_module
    mod = imp.load_module(fullname, self.file, self.filename, self.etc)
  File "/usr/local/lib/python2.7/dist-packages/pwnlib/__init__.py", line 10, in <module>
    from . import \
  File "/usr/local/lib/python2.7/dist-packages/pwnlib/asm.py", line 45, in <module>
    from . import log
  File "/usr/local/lib/python2.7/dist-packages/pwnlib/log.py", line 69, in <module>
    from .term      import spinners, text
  File "/usr/local/lib/python2.7/dist-packages/pwnlib/term/__init__.py", line 1, in <module>
    from . import key, readline, text, termcap, keymap, term
  File "/usr/local/lib/python2.7/dist-packages/pwnlib/term/readline.py", line 2, in <module>
    from . import term, text
  File "/usr/local/lib/python2.7/dist-packages/pwnlib/term/text.py", line 111, in <module>
    sys.modules[__name__] = Module()
  File "/usr/local/lib/python2.7/dist-packages/pwnlib/term/text.py", line 22, in __init__
    self.num_colors = termcap.get('colors', default = 8)
  File "/usr/local/lib/python2.7/dist-packages/pwnlib/term/termcap.py", line 15, in get
    init()
  File "/usr/local/lib/python2.7/dist-packages/pwnlib/term/termcap.py", line 39, in init
    curses.setupterm()
TypeError: argument must be an int, or have a fileno() method.

but with the python, ipython it runs OK.
ipython interpreter

In [1]: from pwn import *
In [2]: 

python default interpreter

>>> from pwn import *
>>> 
≻ bpython -V
bpython version 0.15 on top of Python 2.7.11+
(C) 2008-2015 Bob Farrell, Andreas Stuehrk et al. See AUTHORS for detail.

So it's not the problem with the pwn module, how can solve this problem? it's the bpython bug ? is anyone has problem with me,please tell me how to solve.thanks

Activity

  1. not-napoleon commented on Jun 3, 2016

    @not-napoleon

    I'm having the same issue trying to use ansible:

    >>> from ansible.inventory import Inventory
    Traceback (most recent call last):
      File "<input>", line 1, in <module>
        from ansible.inventory import Inventory
      File ".../lib/python2.7/site-packages/ansible/inventory/__init__.py", line 36, in <module>
        from ansible.plugins import vars_loader
      File ".../lib/python2.7/site-packages/ansible/plugins/__init__.py", line 38, in <module>
        from ansible.utils.display import Display
      File ".../lib/python2.7/site-packages/ansible/utils/display.py", line 37, in <module>
        from ansible.utils.color import stringc
      File ".../lib/python2.7/site-packages/ansible/utils/color.py", line 32, in <module>
        curses.setupterm()
    TypeError: argument must be an int, or have a fileno() method.
    bpython -V
    bpython version 0.15 on top of Python 2.7.11
    (C) 2008-2015 Bob Farrell, Andreas Stuehrk et al. See AUTHORS for detail.
    

    As with the OP, it works fine from ipython.

  2. calebstewart commented on Jun 5, 2016

    @calebstewart
    Contributor

    The issue is that bpython replaces sys.stdout with an object called FakeOutput and somewhere down the line in pwntools, tries to blindly use the sys.stdout.fileno method. According to the standard, this method is not required. The only thing that is required of sys.stdout is a write method. That being said, I've created a fix for this as seen in this pull request. It's not the best solution, since FakeInput shouldn't be required to implement this, but it doesn't break anything and allows you to import pwntools. I'd say it's a good compromise. My fix also will correctly return 1 for sys.stdout and 2 for sys.stderr.

    That being said, logging with pwntools will still be broken, because curtsies does not properly parse the reset escape sequence. Again, I've created a pull request for curtsies to correct this issue as well. With both of these changes, importing pwntools works great on my machine.

  3. B0y1n4o4 commented on Jun 6, 2016

    @B0y1n4o4
    Author

    year, now i update the bpython,it works well now. thank you !! @caleb1994

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions