Httpie: HTTPie in Cygwin

Created on 25 Mar 2016  路  8Comments  路  Source: httpie/httpie

Hi,

i've installed httpie on windows through pip.
I want to use it through cygwin but it only works through powershell or cmd.
I always get the error

Philipp@lupimi ~ $ http POST http://localhost:50231/api/Contact name=scott age:=100
usage: http-script.py [--json] [--form] [--pretty {all,colors,format,none}]
                      [--style STYLE] [--print WHAT] [--headers] [--body]
                      [--verbose] [--all] [--print-others WHAT] [--stream]
                      [--output FILE] [--download] [--continue]
                      [--session SESSION_NAME_OR_PATH | --session-read-only SESSION_NAME_OR_PATH]
                      [--auth USER[:PASS]] [--auth-type {basic,digest}]
                      [--proxy PROTOCOL:PROXY_URL] [--follow]
                      [--max-redirects MAX_REDIRECTS] [--timeout SECONDS]
                      [--check-status] [--verify VERIFY]
                      [--ssl {ssl2.3,ssl3,tls1,tls1.1,tls1.2}] [--cert CERT]
                      [--cert-key CERT_KEY] [--ignore-stdin] [--help]
                      [--version] [--traceback] [--debug]
                      [METHOD] URL [REQUEST_ITEM [REQUEST_ITEM ...]]
http-script.py: error: Request body (from stdin or a file) and request data (key=value) cannot be mixed.

is there anything i can provide?

regards

windows

Most helpful comment

@celevra It looks like stdin under Cygwin doesn't present itself like a TTY so HTTPie thinks it's redirected from another program or a file. So it's probably a bug in Cygwin. What output does this command give you?

$ python -c 'import sys; print(sys.stdin.isatty())'

As a workaround, you could use the --ignore-stdin flag. And for convenience, it can be added it to your ~/.httpie/config.json under "default_options": ["--ignore-stdin"]. Then to enable the reading of stdin when you need it for particular invocations, it is possible to disable the flag again via --no-ignore-stdin.

All 8 comments

age = 100 ??
If it doesn't work try installing httpie in a virtualenv.

@celevra It looks like stdin under Cygwin doesn't present itself like a TTY so HTTPie thinks it's redirected from another program or a file. So it's probably a bug in Cygwin. What output does this command give you?

$ python -c 'import sys; print(sys.stdin.isatty())'

As a workaround, you could use the --ignore-stdin flag. And for convenience, it can be added it to your ~/.httpie/config.json under "default_options": ["--ignore-stdin"]. Then to enable the reading of stdin when you need it for particular invocations, it is possible to disable the flag again via --no-ignore-stdin.

@jkbrzt thanks for the fast answer.
the command gives me a False back.
Do you really think its a bug in Cygwin? Woudn't that be huge problem for other programms also?

the workaround works like a charm, thanks for that

@celevra yep, I think it's Cygwin. It might be that only Python is affected by that, but the sys.stdin.isatty() method should return True since sys.stdin refers to a terminal. I'm not a Cygwin user but it'd be worth reporting to its developers.

If it only affects Python, _definitely_ a bug. If Cygwin just never presents itself as a TTY, I could imagine someone saying this was a design decision not a bug. But geez. What a deviation from normal Linux and bash expectations.

In any case, this is surprising ... but good to find. Oh, Cygwin...

It's worth asking: should HTTPie check sys.stdin.isatty() and if it returns False, then default to --ignore-stdin (perhaps with a WARN-level log message)?

Python for windows is a windows console application, so it won't work well in msys/cygwin's ansi terminal.

You may use python for cygwin rather than python for windows,

$ apt-cyg install python
$ python -c 'import sys; print(sys.stdin.isatty())' # => True

Or, you may run python for windows with winpty:

$ python.exe -c 'import sys; print(sys.stdin.isatty())' # => False
$ winpty python.exe -c 'import sys; print(sys.stdin.isatty())' # => True

Thanks for the tips, @Arnie97. I'm closing this now as there's nothing HTTPie can do about that.

Was this page helpful?
0 / 5 - 0 ratings