Httpie挂在Git的Bash的终端在Windows 10

问题描述:

根据官方documentation httpie工具也适用于Windows 10,但是当我在终端运行命令它只是挂起并没有任何反应:Httpie挂在Git的Bash的终端在Windows 10

$ http :8000/ 

是否有解释发生了什么,最好是解决方法?

我能够通过附加--debug参数得到一个提示:

$ http localhost:8000 --debug 
HTTPie 0.9.9 
Requests 2.12.4 
Pygments 2.1.3 
Python 3.4.4 (v3.4.4:737efcadf5a6, Dec 20 2015, 20:20:57) [MSC v.1600 64 bit (AMD64)] 
c:\users\...\venv\scripts\python.exe 
Windows 10 

<Environment { 
    "colors": 256, 
    "config": { 
    "__meta__": { 
     "about": "HTTPie configuration file", 
     "help": "https://httpie.org/docs#config", 
     "httpie": "0.9.9" 
    }, 
    "default_options": "[]" 
    }, 
    "config_dir": "C:\\Users\\...\\AppData\\Roaming\\\\httpie", 
    "is_windows": true, 
    "stderr": "<colorama.ansitowin32.StreamWrapper object at 0x0000000003CDAB00>", 
    "stderr_isatty": false, 
    "stdin": "<_io.TextIOWrapper name='<stdin>' mode='r' encoding='cp1252'>", 
    "stdin_encoding": "cp1252", 
    "stdin_isatty": false, 
    "stdout": "<colorama.ansitowin32.StreamWrapper object at 0x0000000003CDA9B0>", 
    "stdout_encoding": "cp1252", 
    "stdout_isatty": false 
}> 

关键的一点是,isatty相关选项设置为false

我能甲阶酚醛树脂,并获得http工作由前面加上winpty命令如预期:

$ winpty http :8000 
HTTP/1.0 200 OK 
Content-Type: application/json 
Date: Fri, 16 Dec 2016 19:56:58 GMT 
Server: WSGIServer/0.2 CPython/3.4.4 
X-Frame-Options: SAMEORIGIN 

{ 
    "status": "ok" 
} 

解决方案:

通过添加此别名行

alias http='winpty http' 

~/.profile文件,可以使用初始命令http作为ex与git bash

+1

这是[Git for Windows中的错误](https://github.com/git-for-windows/git/issues/778)。为了使解决方法更简单,你可以在''config.json''的'default_options'列表中添加''--ignore-stdin''(在'C:\\ Users \\ ... \\ AppData \\ Roaming \\\\ httpie')。然后,HTTPie不会尝试读取“stdin”,除非该选项使用“--no-ignore-stdin”进行恢复。 –

+1

@jkbrzt谢谢你的答案,非常感谢。我通过在'〜/ .profile'文件中加入这一行'alias http ='winpty http''添加了一个别名。现在,我可以按照预期使用初始命令。 –