How to send parameters in bitstamp api using python requests module
<p>I am trying to use Bitstamp api and am able to successfully call any thing that only requires key, signature, and nonce parameters. However, when I try transferring or ordering, which require additional parameters like address or price and amount, my request seems to get messed up. I am new to programming, apis and requests. </p>

<pre><code>def sell(self, product):
    nonce = self.get_nonce() #an integer time.time()*10000
    btc = self.get_btc_bal() #float
    price = self.get_btcusd_bid() #float
    amount = float(str(btc)[:5]) 
    message = str(nonce) + self.customer_id + self.api_key
    signature = hmac.new(self.api_secret, msg=message, digestmod=hashlib.sha256).hexdigest().upper()
    r = requests.post(self.url + 'sell/btcusd/', params={'key':self.api_key, 'signature':signature, 'nonce': nonce, 'amount': amount, 'price':price})
    r = r.json()
    print(r)
    print('open sell order in Bitstamp for %s BTC at %s USD'%(amount,price))
</code></pre>

<p>My exact question is how to format/organize/code the parameters correctly. when i send it like so, it returns </p>

<pre><code>{"status": "error", "reason": "Missing key, signature and nonce parameters.", "code": "API0000"}
</code></pre>

<p>if i don't use <code>params=</code> it returns</p>

<pre><code>{"status": "error", "reason": "Invalid nonce", "code": "API0004"}
</code></pre>

<p>I don't believe the nonce reason because I use the exact same get_nonce() method for all my requests. I hope someone can see where I am wrong please and thank you</p>

<p>You should be using <em>data =</em> not <em>params</em>:</p>

<pre><code>requests.post(self.url + 'sell/btcusd/', data={'key':self.api_key, 'signature':signature, 'nonce': nonce, 'amount': amount, 'price':price})
</code></pre>

<p>When you use <em>data =</em>, the data is sent in the body of the request:</p>

<pre><code>In [17]: req = requests.post("https://httpbin.org/post", data=data)

In [18]: req.request.body
Out[18]: 'foo=bar'

In [19]: req.json()
Out[19]: 
{u'args': {},
 u'data': u'',
 u'files': {},
 u'form': {u'foo': u'bar'},
 u'headers': {u'Accept': u'*/*',
  u'Accept-Encoding': u'gzip, deflate',
  u'Content-Length': u'7',
  u'Content-Type': u'application/x-www-form-urlencoded',
  u'Host': u'httpbin.org',
  u'User-Agent': u'python-requests/2.10.0'},
 u'json': None,
 u'origin': u'178.167.254.183',
 u'url': u'https://httpbin.org/post'}
</code></pre>

<p>Using <em>params</em> creates a query string with key/value pairs in the url and the request has no body:</p>

<pre><code>In [21]: req = requests.post("https://httpbin.org/post", params=data)

In [22]: req.request.body

In [23]: req.json()
Out[23]: 
{u'args': {u'foo': u'bar'},
 u'data': u'',
 u'files': {},
 u'form': {},
 u'headers': {u'Accept': u'*/*',
  u'Accept-Encoding': u'gzip, deflate',
  u'Content-Length': u'0',
  u'Host': u'httpbin.org',
  u'User-Agent': u'python-requests/2.10.0'},
 u'json': None,
 u'origin': u'178.167.254.183',
 u'url': u'https://httpbin.org/post?foo=bar'}

In [24]: req.url
Out[24]: u'https://httpbin.org/post?foo=bar'
</code></pre>

python python-requests bitcoin