Skip to content
Advertisement

Every time I run my script it returns `_curses.error: must call setupterm() first` why?

I’m currently trying to learn pwn in python. I wrote a simple Hello world script:

from pwn import *  

io = process('sh') 
io.sendline('echo Hello, world') 
io.recvline()

and let it run. Immediately two errors returned stating:

_curses.error: setupterm: could not find terminfo database
_curses.error: must call (at least) setupterm() first

I’ve looked around and found that the solution ought to be stating:

export TERM=linux
export TERMINFO=/etc/terminfo

Now, export doesn’t seem to be a valid command and placing a forward-slash after an equals sign returns the error 'expression expected'. I’m using pycharm on ubuntu 20.04.

My question then is where do I put the export code?

Advertisement

Answer

In order to run pwntools scripts in non-pty IDEs, the best way is to disable pwntools terminal interaction. This can be done by setting PWNLIB_NOTREM to 1 in the environment. Example from inside the script:

import os
os.environ['PWNLIB_NOTERM'] = '1'

from pwn import *  # the modifications need to happen before this import

# code follows

The same way you can set up other environment variables, like the TERM you mentioned. export TERM=linux is a POSIX shell syntax (or bash syntax), while the python syntax for setting an environment variable like this would be:

os.environ['TERM'] = 'linux'
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement