collective / sphinxcontrib-httpexample

Adds example directive for sphinx-contrib httpdomain
23 stars 20 forks source link

JSON request body throws error when Content-Type is specified in the request #24

Closed jblarsen closed 6 years ago

jblarsen commented 6 years ago

When I try to make this file:

..  http:post:: /

    :reqheader Content-Type: application/json

    **Example request**:

    .. http:example:: curl

        POST / HTTP/1.0
        Content-Type: application/json

        [1.0]

    **Response:**

    .. sourcecode:: http

        HTTP/1.0 200 OK
        Content-Type: application/json

        [2.0]

I get the following error:

     [exec] Exception occurred:
     [exec]   File "/home/jbl/.local/lib/python3.5/site-packages/sphinxcontrib/httpexample/utils.py", line 41, in ordered
     [exec]     for k, v in sorted(dict_.items()):
     [exec] AttributeError: 'list' object has no attribute 'items'

From what I can see from the code httpexample assumes that at the top level of the JSON request body there must be a JSON object and not e.g. an array. See also:

https://stackoverflow.com/a/5034547

datakurre commented 6 years ago

Thanks for the report. I’m unable to fix this immediately, but hopefully soon.

On 13 Mar 2018, 11.10 +0200, Jesper Baasch-Larsen notifications@github.com, wrote:

When I try to make this file: .. http:post:: /

:reqheader Content-Type: application/json

Example request:

.. http:example:: curl

   POST / HTTP/1.0
   Content-Type: application/json

   [1.0]

Response:

.. sourcecode:: http

   HTTP/1.0 200 OK
   Content-Type: application/json

   [2.0]

I get the following error: [exec] Exception occurred: [exec] File "/home/jbl/.local/lib/python3.5/site-packages/sphinxcontrib/httpexample/utils.py", line 41, in ordered [exec] for k, v in sorted(dict_.items()): [exec] AttributeError: 'list' object has no attribute 'items' From what I can see from the code httpexample assumes that at the top level of the JSON request body there must be a JSON object and not e.g. an array. See also: https://stackoverflow.com/a/5034547 — You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or mute the thread.