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] AttributeError: 'unicode' object has no attribute 'items' #111

Closed byg0n3 closed 7 years ago

byg0n3 commented 7 years ago

As title says, I'm getting exception when trying to fetch/save xml response. Same request works fine with raw httpie. Response example attached at the very end. env:

(http_prompt)  ~/Projects/plex_debug$ python --version 
Python 3.6.0
(http_prompt)  ~/Projects/plex_debug$ pip freeze | grep http
http-prompt==0.9.2
httpie==0.9.9

httpie options:

http://127.0.0.1:32400/video/SVR-DEV> httpie
http http://127.0.0.1:32400/video/SVR-DEV Cookie:com.plexapp.plugins.svr=Y2VyZWFsMQozCmRpY3QKbGlzdApkaWN0CjIKcjEKczcKY29va2llc3IyCnM3CnNlc3Npb24wCjAKcjAK X-Plex-Token:%SOMETOKENHERE%

http-prompt get trace:

http://127.0.0.1:32400/video/SVR-DEV> get
HTTP/1.1 200 OK
Cache-Control: no-cache
Connection: Keep-Alive
Content-Encoding: gzip
Content-Length: 438
Content-Type: application/xml
Date: Wed, 01 Mar 2017 23:02:50 GMT
Etag: "1f5714a7cd820e8a1043cff95a0d10ac63d3760b"
Keep-Alive: timeout=20
Set-Cookie: com.plexapp.plugins.svr=Y2VyZWFsMQozCmRpY3QKbGlzdApkaWN0CjIKcjEKczcKY29va2llc3IyCnM3CnNlc3Npb24wCjAKcjAK
X-Plex-Content-Compressed-Length: 438
X-Plex-Content-Original-Length: 1665
X-Plex-Protocol: 1.0

<?xml version='1.0' encoding='utf-8'?>
<MediaContainer title1="SVR-DEV" art="/:/plugins/com.plexapp.plugins.svr/resources/art-default.jpg?t=1316888148" size="6" identifier="com.plexapp.plugins.svr" sourceTitle="SVR-DEV" mediaTagPrefix="/system/bundle/media/flags/" prefsKey="/:/plugins/com.plexapp.plugins.svr/prefs" searchesKey="/system/services/searches?identifier=com.plexapp.plugins.svr">
  <Directory art="/:/plugins/com.plexapp.plugins.svr/resources/art-default.jpg?t=1316888148" thumb="/:/plugins/com.plexapp.plugins.svr/resources/icon-default.png?t=1316888148" key="/video/SVR-DEV/latest_update_menu" title="LATEST_UPDATES"/>
  <Directory art="/:/plugins/com.plexapp.plugins.svr/resources/art-default.jpg?t=1316888148" thumb="/:/plugins/com.plexapp.plugins.svr/resources/icon-default.png?t=1316888148" key="/video/SVR-DEV/filter_menu" title="FILTER"/>
  <Directory prompt="SEARCH?" key="/video/SVR-DEV/search_input" title="SEARCH" search="1"/>
  <Directory art="/:/plugins/com.plexapp.plugins.svr/resources/art-default.jpg?t=1316888148" thumb="/:/plugins/com.plexapp.plugins.svr/resources/icon-default.png?t=1316888148" key="/video/SVR-DEV/bookmarks_menu" title="BOOKMARKS"/>
  <Directory art="/:/plugins/com.plexapp.plugins.svr/resources/art-default.jpg?t=1316888148" thumb="/:/plugins/com.plexapp.plugins.svr/resources/icon-default.png?t=1316888148" key="/video/SVR-DEV/history_menu" title="HISTORY"/>
  <Directory art="/:/plugins/com.plexapp.plugins.svr/resources/art-default.jpg?t=1316888148" thumb="/:/plugins/com.plexapp.plugins.svr/resources/icon-default.png?t=1316888148" key="/video/SVR-DEV/advanced_menu" title="ADVANCED_MENU"/>
</MediaContainer>

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 "">

http-prompt get&save trace:

http://127.0.0.1:32400/video/SVR-DEV> get > ./test.xml
AttributeError: 'unicode' object has no attribute 'items'

Parse tree:
<Node called "action" matching "get > ./test.xml">  <-- *** We were here. ***
    <RegexNode called "_" matching "">
    <Node called "method" matching "get">
        <RegexNode matching "get">
    <RegexNode called "_" matching " ">
    <Node matching "">
    <Node matching "">
    <Node matching "> ./test.xml">
        <Node called "redir_out" matching "> ./test.xml">
            <Node called "redir_write" matching "> ./test.xml">
                <RegexNode called "_" matching "">
                <Node matching ">">
                <RegexNode called "_" matching " ">
                <Node called "string" matching "./test.xml">
                    <Node called "unquoted_string" matching "./test.xml">
                        <Node called "unquoted_stringitem" matching ".">
                            <RegexNode called "unquoted_stringchar" matching ".">
                        <Node called "unquoted_stringitem" matching "/">
                            <RegexNode called "unquoted_stringchar" matching "/">
                        <Node called "unquoted_stringitem" matching "t">
                            <RegexNode called "unquoted_stringchar" matching "t">
                        <Node called "unquoted_stringitem" matching "e">
                            <RegexNode called "unquoted_stringchar" matching "e">
                        <Node called "unquoted_stringitem" matching "s">
                            <RegexNode called "unquoted_stringchar" matching "s">
                        <Node called "unquoted_stringitem" matching "t">
                            <RegexNode called "unquoted_stringchar" matching "t">
                        <Node called "unquoted_stringitem" matching ".">
                            <RegexNode called "unquoted_stringchar" matching ".">
                        <Node called "unquoted_stringitem" matching "x">
                            <RegexNode called "unquoted_stringchar" matching "x">
                        <Node called "unquoted_stringitem" matching "m">
                            <RegexNode called "unquoted_stringchar" matching "m">
                        <Node called "unquoted_stringitem" matching "l">
                            <RegexNode called "unquoted_stringchar" matching "l">
                <RegexNode called "_" matching "">
    <RegexNode called "_" matching "">

Same requests with raw httpie:

(http_prompt)  ~/Projects/plex_debug$ http http://127.0.0.1:32400/video/SVR-DEV Cookie:com.plexapp.plugins.svr=Y2VyZWFsMQozCmRpY3QKbGlzdApkaWN0CjIKcjEKczcKY29va2llc3IyCnM3CnNlc3Npb24wCjAKcjAK X-Plex-Token:%SOMETOKENHERE%
HTTP/1.1 200 OK
Cache-Control: no-cache
Connection: Keep-Alive
Content-Encoding: gzip
Content-Length: 438
Content-Type: application/xml
Date: Wed, 01 Mar 2017 23:09:18 GMT
Etag: "1f5714a7cd820e8a1043cff95a0d10ac63d3760b"
Keep-Alive: timeout=20
Set-Cookie: com.plexapp.plugins.svr=Y2VyZWFsMQozCmRpY3QKbGlzdApkaWN0CjIKcjEKczcKY29va2llc3IyCnM3CnNlc3Npb24wCjAKcjAK
X-Plex-Content-Compressed-Length: 438
X-Plex-Content-Original-Length: 1665
X-Plex-Protocol: 1.0

<?xml version='1.0' encoding='utf-8'?>
<MediaContainer title1="SVR-DEV" art="/:/plugins/com.plexapp.plugins.svr/resources/art-default.jpg?t=1316888148" size="6" identifier="com.plexapp.plugins.svr" sourceTitle="SVR-DEV" mediaTagPrefix="/system/bundle/media/flags/" prefsKey="/:/plugins/com.plexapp.plugins.svr/prefs" searchesKey="/system/services/searches?identifier=com.plexapp.plugins.svr">
  <Directory art="/:/plugins/com.plexapp.plugins.svr/resources/art-default.jpg?t=1316888148" thumb="/:/plugins/com.plexapp.plugins.svr/resources/icon-default.png?t=1316888148" key="/video/SVR-DEV/latest_update_menu" title="LATEST_UPDATES"/>
  <Directory art="/:/plugins/com.plexapp.plugins.svr/resources/art-default.jpg?t=1316888148" thumb="/:/plugins/com.plexapp.plugins.svr/resources/icon-default.png?t=1316888148" key="/video/SVR-DEV/filter_menu" title="FILTER"/>
  <Directory prompt="SEARCH?" key="/video/SVR-DEV/search_input" title="SEARCH" search="1"/>
  <Directory art="/:/plugins/com.plexapp.plugins.svr/resources/art-default.jpg?t=1316888148" thumb="/:/plugins/com.plexapp.plugins.svr/resources/icon-default.png?t=1316888148" key="/video/SVR-DEV/bookmarks_menu" title="BOOKMARKS"/>
  <Directory art="/:/plugins/com.plexapp.plugins.svr/resources/art-default.jpg?t=1316888148" thumb="/:/plugins/com.plexapp.plugins.svr/resources/icon-default.png?t=1316888148" key="/video/SVR-DEV/history_menu" title="HISTORY"/>
  <Directory art="/:/plugins/com.plexapp.plugins.svr/resources/art-default.jpg?t=1316888148" thumb="/:/plugins/com.plexapp.plugins.svr/resources/icon-default.png?t=1316888148" key="/video/SVR-DEV/advanced_menu" title="ADVANCED_MENU"/>
</MediaContainer>

response_example.zip

eliangcs commented 7 years ago

@dein0s I can't reproduce the bug with http://httpbin.org/xml. Here's what we can do next:

1) Can you show me your full pip freeze? 2) Are you able to reproduce the bug with a public accessible server? If not, can you provide your server-side code that can reproduce the bug?

byg0n3 commented 7 years ago

Well, the first one is easy :)

(http_prompt)  ~/Projects $ pip freeze
click==6.7
decorator==4.0.11
http-prompt==0.9.2
httpie==0.9.9
ipython==5.3.0
ipython-genutils==0.1.0
parsimonious==0.7.0
pexpect==4.2.1
pickleshare==0.7.4
prompt-toolkit==1.0.13
ptyprocess==0.5.1
Pygments==2.2.0
requests==2.13.0
simplegeneric==0.8.1
six==1.10.0
traitlets==4.3.2
wcwidth==0.1.7

About second - I don't have enough experience yet with http-prompt, switched to it only few weeks ago from httpie. I can't reproduce this exception on public servers and I'm not sure that I can provide you a server-side code right now as it is internal API for Plex Media Server and I use it only to debug my own plugin. I can try to dig around, but their framework is a big mess and has no up-to-date docs (last version is 6 years old and removed from official site) :| So I'm not sure that I'll be able to find it any time soon.

eliangcs commented 7 years ago

@dein0s The exception traceback is swallowed so it's not easy to debug. Here's another thing you can help. Add a line of code at line 523 in execute.py, so that:

original:

            else:
                # TODO: Better error message
                click.secho(str(err), err=True, fg='red')
        except CalledProcessError as err:
            click.secho(err.output + ' (exit status %d)' % err.returncode,
                        fg='red')

after:

            else:
                # TODO: Better error message
                click.secho(str(err), err=True, fg='red')
            raise   # <-- ADD THIS LINE
        except CalledProcessError as err:
            click.secho(err.output + ' (exit status %d)' % err.returncode,
                        fg='red')

Then retry what you did. This time the traceback should be printed. Paste the traceback here. It allows us to see where the error occurred.

byg0n3 commented 7 years ago

Okay, looks like the problem was on server (my) side as there were an update for Plex Server and after installing it I can't reproduce this exception. I'll try to downgrade server version and test this issue again later on today.

byg0n3 commented 7 years ago

Damn, still can't reproduce it, even rolled back the whole machine state from snapshot. Guess it was just some local magic, closed.