Python: Properly formatting JSON parameters into a proper http request with markit on demand api
<p>I am having trouble formatting my request properly in order to use the markitondemand InteractiveChart API.  How can I properly do this?</p>

<p>reference: <a href="http://dev.markitondemand.com/MODApis/" rel="nofollow">http://dev.markitondemand.com/MODApis/</a></p>

<p>Here is an example of a proper request:</p>

<pre><code>http://dev.markitondemand.com/MODApis/Api/v2/InteractiveChart/json?parameters=%7B%22Normalized%22%3Afalse%2C%22NumberOfDays%22%3A10%2C%22DataPeriod%22%3A%22Day%22%2C%22Elements%22%3A%5B%7B%22Symbol%22%3A%22AAPL%22%2C%22Type%22%3A%22price%22%2C%22Params%22%3A%5B%22c%22%5D%7D%5D%7D
</code></pre>

<p>Here is my code constructing a request:</p>

<pre><code>import requests
import json        
url2 = 'http://dev.markitondemand.com/MODApis/Api/v2/InteractiveChart/json'
elements = [
        {
            'Symbol': 'GOOG',
            'Type': 'price',
            'Params': {'price': ['c']},
        }
    ]

req_obj = {
    'Normalized': 'false',
    'NumberOfDays': 3,
    'DataPeriod': 'Day',
    'Elements': elements
}

resp = requests.get(url2, params={'parameters': json.dumps(req_obj)})
</code></pre>

<p>and here is the output when I log the resp.url :</p>

<pre><code>http://dev.markitondemand.com/MODApis/Api/v2/InteractiveChart/json?parameters=%7B%22Elements%22%3A+%5B%7B%22Type%22%3A+%22price%22%2C+%22Params%22%3A+%7B%22price%22%3A+%5B%22c%22%5D%7D%2C+%22Symbol%22%3A+%22GOOG%22%7D%5D%2C+%22NumberOfDays%22%3A+3%2C+%22DataPeriod%22%3A+%22Day%22%2C+%22Normalized%22%3A+%22false%22%7D
</code></pre>

<p>What am I doing wrong here?</p>

<p>Your url end point (by the looks of it) should just be:</p>

<pre><code>url2 = 'http://dev.markitondemand.com/MODApis/Api/v2/InteractiveChart
</code></pre>

<p>Then, make your request:</p>

<pre><code>resp = requests.get(url2, params=json.dumps({'parameters': req_obj}))
</code></pre>

<p>Then <code>requests</code> will properly handle the <code>?</code> and any <code>&amp;</code> if they were required.</p>

python json