title: POSTing json data with grequests?
body: <p>I need to make async POST requests with grequests.</p>
  
  <p>My post body (in json), is this:</p>
  
  <pre><code>[{'params': {'source': 'widget',
     'id': 'http://us.i1.yimg.com/us.yimg.com/i/ww/beta/y3.gif',
     'groupId': '@self',
     'nolog': 'true',
     'userId': '@viewer'},
    'method': 'pos.plusones.get',
    'id': 'p',
    'jsonrpc': '2.0',
    'apiVersion': 'v1',
    'key': 'p'}]
  </code></pre>
  
  <p>I need to change <code>[0]['params']['id']</code> key's value to different URLs for the many POSTs I'll make.</p>
  
  <p>So I'm doing:</p>
  
  <p><code>myrequests = (grequests.post(POST_URL, data=fgp(a_url) for a_url in all_urls)
  </code></p>
  
  <p>The <code>fgp()</code> method in my generator comprehension is a method that changes the <code>[0]['params']['id']</code> to the <code>a_url</code> passed to it, in the POST body I'm sending.</p>
  
  <p>And when I map the requests to responses:</p>
  
  <p><code>myresponses = grequests.map(myrequests)</code></p>
  
  <p>This is what I get, as many times as there are requests (obviously).</p>
  
  <pre><code>Traceback (most recent call last):
    File "/home/ashk/.virtualenvs/cosignp3/src/gevent/gevent/greenlet.py", line 340, in run
      result = self._run(*self.args, **self.kwargs)
    File "/home/ashk/.virtualenvs/cosignp3/lib/python3.4/site-packages/grequests.py", line 71, in send
      self.url, **merged_kwargs)
    File "/home/ashk/.virtualenvs/cosignp3/lib/python3.4/site-packages/requests/sessions.py", line 451, in request
      prep = self.prepare_request(req)
    File "/home/ashk/.virtualenvs/cosignp3/lib/python3.4/site-packages/requests/sessions.py", line 382, in prepare_request
      hooks=merge_hooks(request.hooks, self.hooks),
    File "/home/ashk/.virtualenvs/cosignp3/lib/python3.4/site-packages/requests/models.py", line 307, in prepare
      self.prepare_body(data, files, json)
    File "/home/ashk/.virtualenvs/cosignp3/lib/python3.4/site-packages/requests/models.py", line 456, in prepare_body
      body = self._encode_params(data)
    File "/home/ashk/.virtualenvs/cosignp3/lib/python3.4/site-packages/requests/models.py", line 89, in _encode_params
      for k, vs in to_key_val_list(data):
  ValueError: too many values to unpack (expected 2)
  &lt;Greenlet at 0x7f0f7cbf33d8: &lt;bound method AsyncRequest.send of &lt;grequests.AsyncRequest object at 0x7f0f7c90d080&gt;&gt;(stream=False)&gt; failed with ValueError
  </code></pre>
  
  <p><strong>EDIT: Problem solved</strong> :-</p>
  
  <p>I got to playing around, and put in the headers just like you would in the <code>requests</code> module.</p>
  
  <p>I'm setting the headers kwarg argument to make encoding none, and content-type:</p>
  
  <pre><code>(grequests.post(POST_URL, data=fgp(a_url, j=True), headers={'Accept-Encoding':'none', 'Content-Type':'application/json'}) for a_url in urls)
  </code></pre>
  
  <p>And now I'm getting the output correctly:</p>
  
  <pre><code>In [64]: resps[0].json()
  Out[64]: 
  {'result': {'isSetByViewer': False,
    'kind': 'pos#plusones',
    'metadata': {'type': 'URL', 'globalCounts': {'count': 0.0 }},
    'id': 'http://example.com/dfg',
    'abtk': 'xxxxxxxxxxxxxxx'},
   'id': 'p'}
  </code></pre>
  
  <p>Note: Output edited a little bit to hide some data.</p>