httpie / http-prompt

An interactive command-line HTTP and API testing client built on top of HTTPie featuring autocomplete, syntax highlighting, and more. https://twitter.com/httpie
https://http-prompt.com
MIT License
8.96k stars 326 forks source link

[Bug] Cookie related AttributeError under Python 2 #126

Closed richboss closed 6 years ago

richboss commented 7 years ago

Using http-prompt version 0.10.2 under Python 2.7, an AttributeError occurs as soon as a stored cookie is updated. The error doesn't seem to depend on the operating system. Tested on Windows 10 (native and with Cygwin) and with Arch Linux.

To reproduce:

This is the full error message:

    AttributeError: 'unicode' object has no attribute 'items'

    Parse tree:
    <Node called "action" matching "get">  <-- *** We were here. ***
        <RegexNode called "_" matching "">
        <Node called "method" matching "get">
            <RegexNode matching "get">
        <RegexNode called "_" matching "">
        <Node matching "">
        <Node matching "">
        <Node matching "">
        <RegexNode called "_" matching "">

I managed to locate the precise spot where the error occurs. It is in the function update_cookies(base_value, cookies), which is in the module cli.py. The root cause seems to be that base_value needs to be a string (or None, initially). But under Python 2 the type of base_value is unicode. A solution that works for me is to insert the following two lines at the begin of that function:

        if type(base_value) == unicode:
            base_value = base_value.encode('utf8') 

But this really is not much more than a hackish workaround. I'd like to have it properly fixed.

eliangcs commented 6 years ago

Fixed in #145, shipped in v1.0.0.