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

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

Open
iamdejan opened this issue Aug 2, 2017 · 3 comments
Open

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

iamdejan opened this issue Aug 2, 2017 · 3 comments

Comments

@iamdejan
Copy link

iamdejan commented Aug 2, 2017

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.

@arthaud
Copy link
Owner

arthaud commented Aug 5, 2017

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 *

@iamdejan
Copy link
Author

iamdejan commented Sep 8, 2017

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

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

3 participants
@arthaud @iamdejan and others