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

[Bug] Cookie related AttributeError under Python 2 #126

Closed
richboss opened this issue Aug 3, 2017 · 1 comment
Closed

[Bug] Cookie related AttributeError under Python 2 #126

richboss opened this issue Aug 3, 2017 · 1 comment
Labels

Comments

@richboss
Copy link

richboss commented Aug 3, 2017

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:

  • Open any site that stores a cookie, e.g.: http-prompt https://www.google.com --follow
  • Make a GET request. If http-prompt is configured to automatically store cookies, then a cookie will be stored.
  • Repeat the GET request. An AttributeError occurs, displayed immediately after the response output.

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 eliangcs added the bug label Aug 4, 2017
KiranBaktha added a commit to KiranBaktha/http-prompt that referenced this issue Sep 25, 2018
@eliangcs
Copy link
Contributor

eliangcs commented Nov 4, 2018

Fixed in #145, shipped in v1.0.0.

@eliangcs eliangcs closed this as completed Nov 4, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants