Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

httpie output has lots of additional characters on windows #36

Closed
obmarg opened this issue Mar 19, 2012 · 20 comments
Closed

httpie output has lots of additional characters on windows #36

obmarg opened this issue Mar 19, 2012 · 20 comments
Labels
bug Something isn't working windows Windows specific issue

Comments

@obmarg
Copy link

obmarg commented Mar 19, 2012

Running http GET httpie.org on windows results in a load of extra characters being printed out:

HTTP/1.1 ←[39;49;00m←[34m302←[39;49;00m←[33m Found←[39;49;00m
Date:←[39;49;00m←[33m Mon, 19 Mar 2012 15:13:17 GMT←[39;49;00m
Server:←[39;49;00m←[33m Apache←[39;49;00m
X-Awesome:←[39;49;00m←[33m Thanks for trying HTTPie :)←[39;49;00m
Location:←[39;49;00m←[33m https://github.com/jkbr/httpie←[39;49;00m
Cache-Control:←[39;49;00m←[33m max-age=1800←[39;49;00m
Expires:←[39;49;00m←[33m Mon, 19 Mar 2012 15:43:17 GMT←[39;49;00m
Content-Length:←[39;49;00m←[33m 214←[39;49;00m
Content-Type:←[39;49;00m←[33m text/html; charset=iso-8859-1←[39;49;00m

←[36m<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">←[39;49;00m
←[34;01m<html←[39;49;00m←[34;01m>←[39;49;00m←[34;01m<head←[39;49;00m←[34;01m>←[39;49;00m
←[34;01m<title←[39;49;00m←[34;01m>←[39;49;00m302 Found←[39;49;00m←[34;01m</title>←[39;49;00m
←[34;01m</head>←[39;49;00m←[34;01m<body←[39;49;00m←[34;01m>←[39;49;00m
←[34;01m<h1←[39;49;00m←[34;01m>←[39;49;00mFound←[39;49;00m←[34;01m</h1>←[39;49;00m
←[34;01m<p←[39;49;00m←[34;01m>←[39;49;00mThe document has moved ←[39;49;00m←[34;01m<a←[39;49;00m ←[39;49;00m←[36mhref=←[39;49;00m←[33m"https://github.com/jkbr/httpie"←[39;49;00m←[34;01m>←[39;49;00mhere←[39;49;00m←[34;01m</a>←[39;49;00m.←[39;49;00m←[34;01m</p>←[39;49;00m

I'm guessing that these are escape codes that provide the colored output on other operating systems. Running http -u GET httpie.org results in correct (though monochrome) output.

It'd be nice to get cross platform colored output like provided by clint.

@lllama
Copy link

lllama commented May 8, 2012

It does look like the colorama module could be a fairly simple way to address this:
http://pypi.python.org/pypi/colorama

@dethstryke
Copy link

Bummed to find this bug, colored output would be nice.

@jkbrzt jkbrzt closed this as completed in 2dba176 Jul 17, 2012
@jkbrzt
Copy link
Member

jkbrzt commented Jul 17, 2012

This should be fixed now. Thanks for the tip for colorama, it works very well. I've tested it on Python 2.7 under Windows 7 with PowerShell and cmd.exe.

It would be great if you could test it and provide feedback (I don't use Windows very often):

pip install -U https://github.com/jkbr/httpie/tarball/master

There is one remaining Windows-related issue (unicode in terminal #71).

httpie on windows

@obmarg
Copy link
Author

obmarg commented Jul 17, 2012

I've just tested with powershell, zsh & cmd.exe using Python 2.7 - seems to work perfectly. Thanks for the fix.

@jkbrzt
Copy link
Member

jkbrzt commented Jul 17, 2012

Glad to hear that. Thanks for the feedback.

@GuiSim
Copy link

GuiSim commented Jul 18, 2012

I get the following warnings when running httpie under PyPy 1.6 :

path\to\colorama\win32.py:17: RuntimeWarning: C function without declared arguments called
  STDOUT: windll.kernel32.GetStdHandle(STDOUT),
path\to\colorama\win32.py:18: RuntimeWarning: C function without declared arguments called
  STDERR: windll.kernel32.GetStdHandle(STDERR),
path\to\colorama\win32.py:64: RuntimeWarning: C function without declared arguments called
  handle, byref(csbi))
path\to\colorama\win32.py:70: RuntimeWarning: C function without declared arguments called
  return windll.kernel32.SetConsoleTextAttribute(handle, attrs)

I think that this is caused by PyPy (see http://mail.python.org/pipermail/pypy-commit/2011-April/049781.html)
but I suspect that the code could be changed to avoid this warning.

EDIT: Nevermind, these warnings are coming from Colorama.

http://code.google.com/p/colorama/issues/detail?id=26

@dethstryke
Copy link

I'm still getting this using ActivePython 3.2.2.3 I ran the update command you listed and am still getting the same output as before. Am I missing anything?

@jkbrzt
Copy link
Member

jkbrzt commented Jul 19, 2012

@dethstryke What is the output of http --version? If it says something else than 0.2.6dev, then please try to uninstall the old version first and then install the dev one again:

pip uninstall httpie
pip install -U https://github.com/jkbr/httpie/tarball/master

@kaplas
Copy link

kaplas commented Jul 19, 2012

I'm sorry that I didn't notice this issue thread when making the pull request. Also when I named my fork, I didn't know that you have already included colorama in the project. However, the dev branch did not work for me. (http --version gives 0.2.6dev for me) As I mention in my pull request, I had to change the stdout writing to a single print statement to get it working.

As a proof, here's a screenshot showing installation from the dev branch (on the left) and then from my fork (on the right):
http://grab.by/eRsq

I also had to install 'requests' separately, because the one provided by pip didn't work on my system. But by installing requests directly from their git repo worked flawesly.

I'm totally newbie with python, pip and colorama, and quite newbie also with github, so I'm sorry if this is just some Stupid User Error. But I still think that there is something wrong with outputting to the cmd.exe window, and my pull request seems to fix it.

@mieky
Copy link

mieky commented Jul 19, 2012

At a quick glance it would seem that a simple 'print output' (without any explicit encoding being done) works nicely on both Windows and OS X. I just want to understand the details involved - what would break if we were to remove the check for stdout.buffer and/or the encoding parts?

@jkbrzt
Copy link
Member

jkbrzt commented Jul 19, 2012

@mieky Encoding the output ensures that unicode characters (like ě, not colors) are displayed correctly on the terminal. The way it's done now seems to work well under OS X and Linux on all the supported Pythons, but on Windows it's still displayed incorrectly (#71).

The color problem that some people are still seing on Windows is most likely caused by the fact that colorama is unable to process the output on some configurations (due to the way it's being written/encoded for OSX/Linux).

So, @cido's patch seems to solve the occasional color-related problems on Windows, but the output still needs to be encoded (somehow) to ensure that unicode works.

It's quite tricky to solve it universally. Any help appreciated.

@mariodev
Copy link

@jkbr Is there any changes I need to make to my win cmd.exe to prettify the output? Since I've installed 0.2.6-dev and still I get escape codes..

jkbrzt added a commit that referenced this issue Jul 21, 2012
@jkbrzt
Copy link
Member

jkbrzt commented Jul 21, 2012

Please try the current master:

pip install -U https://github.com/jkbr/httpie/tarball/master

@mariodev
Copy link

@jkbr Thank you, that worked.

@jkbrzt
Copy link
Member

jkbrzt commented Jul 26, 2012

This seems to be fixed in 0.2.6. Please feel free to reopen this issue if the problem persists.

@jkbrzt jkbrzt closed this as completed Jul 26, 2012
@hickford
Copy link
Contributor

Thanks

pip install --upgrade httpie

@mykwillis
Copy link

I'm not sure if there was a regression of if there is some problem with my local terminal, but the most recent version is showing this behavior for me.

python --version
Python 3.4.3

http --version
0.9.2
←[0m

http httpie.org
←[38;5;33mHTTP←[39m←[38;5;245m/←[39m←[38;5;37m1.1←[39m←[38;5;245m ←[39m←[38;5;37m302←[39m←[38;5;245m ←[39m←[38;5;136mFound←[39m
←[38;5;245mConnection←[39m←[38;5;245m:←[39m←[38;5;245m ←[39m←[38;5;37mclose←[39m
←[38;5;245mContent-Length←[39m←[38;5;245m:←[39m←[38;5;245m ←[39m←[38;5;37m292←[39m
[...]

@bryanbak
Copy link

I just installed this on windows and am having the same issue as @mykwillis, but only in powershell. If I use httpie in the regular cmd prompt it looks fine.

Windows 7
python 2.7.10
httpie 0.9.2

@mykwillis
Copy link

I notice that if I

pip install colorama==0.3.2

as opposed to using the latest colorama (0.3.3), then I don't get the control characters in the output.

It's not in color, but at least it's not garbled.

So this is likely something to do with a change in colorama between 0.3.2 and 0.3.3

@bryanbak
Copy link

Just downgraded colorama to 0.3.2 based on @mykwillis suggestion and powershell output looks much better now. Thanks for the advice!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working windows Windows specific issue
Projects
None yet
Development

No branches or pull requests