python3-pwntools icon indicating copy to clipboard operation
python3-pwntools copied to clipboard

Can't Run "from pwn import *" from Python IDLE

Open iamdejan opened this issue 8 years ago • 3 comments

When I run

from pwn import *

from Python 3.5 IDLE, it gives me error message like:

Traceback (most recent call last): File "<pyshell#0>", line 1, in from pwn import * File "/home/dejanosky/Downloads/python3-pwntools/pwn/init.py", line 2, in from .toplevel import * File "/home/dejanosky/Downloads/python3-pwntools/pwn/toplevel.py", line 19, in import pwnlib File "/home/dejanosky/Downloads/python3-pwntools/pwnlib/init.py", line 37, in importlib.import_module('.%s' % module, 'pwnlib') File "/usr/lib/python3.5/importlib/init.py", line 126, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "/home/dejanosky/Downloads/python3-pwntools/pwnlib/args.py", line 7, in from . import term File "/home/dejanosky/Downloads/python3-pwntools/pwnlib/term/init.py", line 5, in from . import readline File "/home/dejanosky/Downloads/python3-pwntools/pwnlib/term/readline.py", line 3, in from . import term File "/home/dejanosky/Downloads/python3-pwntools/pwnlib/term/term.py", line 30, in fd = sys.stdout.buffer AttributeError: 'PseudoOutputFile' object has no attribute 'buffer'

(dejanosky is my username). What should I do? Thx.

iamdejan avatar Aug 02 '17 09:08 iamdejan

Hi @iamdejan

python3-pwntools uses sys.stdout.buffer.write() to write bytes on the standard output (sys.stdout.write() only takes strings). See https://stackoverflow.com/questions/908331/how-to-write-binary-data-in-stdout-in-python-3

It looks like IDLE doesn't provide sys.stdout.buffer.

We would need to find another way to write bytes on the standard output (maybe fd = os.fdopen(1, 'rb')) and fix the code.

As a short-term solution, you can try:

import sys
import os
sys.stdout.buffer = os.fdopen(1, 'wb')
from pwn import *

arthaud avatar Aug 05 '17 07:08 arthaud

now I get this error: Traceback (most recent call last): File "<pyshell#7>", line 1, in <module> from pwn import * File "/home/dejanosky/Downloads/python3-pwntools/pwn/__init__.py", line 2, in <module> from .toplevel import * File "/home/dejanosky/Downloads/python3-pwntools/pwn/toplevel.py", line 19, in <module> import pwnlib File "/home/dejanosky/Downloads/python3-pwntools/pwnlib/__init__.py", line 37, in <module> importlib.import_module('.%s' % module, 'pwnlib') File "/usr/lib/python3.5/importlib/__init__.py", line 126, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "/home/dejanosky/Downloads/python3-pwntools/pwnlib/args.py", line 7, in <module> from . import term File "/home/dejanosky/Downloads/python3-pwntools/pwnlib/term/__init__.py", line 5, in <module> from . import readline File "/home/dejanosky/Downloads/python3-pwntools/pwnlib/term/readline.py", line 4, in <module> from . import text File "/home/dejanosky/Downloads/python3-pwntools/pwnlib/term/text.py", line 125, in <module> sys.modules[__name__] = Module() File "/home/dejanosky/Downloads/python3-pwntools/pwnlib/term/text.py", line 28, in __init__ self.num_colors = termcap.get('colors', default=8) File "/home/dejanosky/Downloads/python3-pwntools/pwnlib/term/termcap.py", line 23, in get s = curses.tigetstr(cap) _curses.error: must call (at least) setupterm() first

iamdejan avatar Sep 08 '17 03:09 iamdejan