<p>A closer look at their API page, you will find LakeBTC has provided a simple code for Python: <a href="https://github.com/LakeBTC/lakebtc_python" rel="nofollow">https://github.com/LakeBTC/lakebtc_python</a> </p>

<p>And others Sample Code you can find here: <a href="https://www.lakebtc.com/s/api" rel="nofollow">https://www.lakebtc.com/s/api</a> include PHP, Node.JS, Ruby and Python, maybe will more Code in the future :)</p>

CC BY-SA 3.0
2014-10-29T05:07:04.190Z
Nice work! I didn't see that on their API page. +1
Nick ODell
CC BY-SA 3.0
2014-10-30T04:38:38.473Z
Indeed! I actually just received an email from them after they added it!
quannabe
CC BY-SA 3.0
2014-10-29T04:19:07.283Z
2014-10-29T04:19:07.283Z
JuanBllaain
<p>I think I figured out your problem. (Or, one of them, at least.)</p>

<blockquote>
  <p>Step 6: POST params data in JSON format to this url:<br>
  <a href="https://www.LakeBTC.com/api_v1" rel="nofollow">https://www.LakeBTC.com/api_v1</a></p>
</blockquote>

<p>You're not POSTing the the right information; you're POSTing the entire signature.</p>

<pre><code>response = requests.post(self.apiUrl, data=p, headers=header)
</code></pre>

<p>Should be something along the lines of:</p>

<pre><code>response = requests.post(self.apiUrl, data=json.dumps(
    {
        "method": method,
        "params":",".join(params),
        "id": 1,
    }, headers=header)
</code></pre>

CC BY-SA 3.0
2014-10-23T19:22:36.640Z
2014-10-23T19:22:36.640Z
Nick ODell
<p>I'm having trouble following LakeBTC's API instructions for connecting to their API via Python.</p>

<p>API Documentation:
<a href="https://www.lakebtc.com/s/api" rel="nofollow">https://www.lakebtc.com/s/api</a></p>

<p>I have my key (email address) and secret. I'm using the API URL: <a href="https://www.LakeBTC.com/api_v1" rel="nofollow">https://www.LakeBTC.com/api_v1</a></p>

<p>No matter what I try, I get a 401 Error. Below is my code, any ideas?</p>

<pre><code>tonce = str(int(time.time() * 1e6))

p = 'tonce=' + tonce \
    + '&amp;accesskey=' + self.key \
    + '&amp;requestmethod=post' \
    + '&amp;id=1' \
    + '&amp;method=' + 'getAccountInfo' \
    + '&amp;params='

# Create signature
hmac_obj = hmac.new(self.secret, p, hashlib.sha1)

b64 = 'Basic ' + base64.b64encode(self.key + ':' + hmac_obj.digest())

header = {
    'Json-Rpc-Tonce': tonce,
    'Authorization': b64,
    'content-type': 'application/json-rpc',
}

response = requests.post(self.apiUrl, data=p, headers=header)
</code></pre>

<p>Am I encrypting and hashing correctly?</p>

CC BY-SA 3.0
2014-10-23T05:55:09.383Z
What does the returned WWW-Authenticate header say? Is there a body to the response? If so, does it show an error?
Nick ODell
CC BY-SA 3.0
2014-10-23T17:25:50.900Z
No body is returned, here is the returned header: {'status': '401 Unauthorized', 'x-request-id': '94f303be4a3e97e8dc289fbe1881555b', 'x-powered-by': 'Phusion Passenger 4.0.14', 'transfer-encoding': 'chunked', 'x-runtime': '0.002153', 'server': 'nginx/1.6.0', 'connection': 'keep-alive', 'x-ua-compatible': 'IE=Edge,chrome=1', 'cache-control': 'no-cache', 'date': 'Thu, 23 Oct 2014 17:18:16 GMT', 'content-type': 'application/json; charset=utf-8', 'x-rack-cache': 'invalidate, pass'}
quannabe
<api><encryption><hash><authentication><python>
API Authentication via Python
quannabe
# API Authentication via Python

(Asked by: username_0 on 2014-10-23)

I'm having trouble following LakeBTC's API instructions for connecting to their API via Python.

API Documentation:
<https://www.lakebtc.com/s/api>

I have my key (email address) and secret. I'm using the API URL: <https://www.LakeBTC.com/api_v1>

No matter what I try, I get a 401 Error. Below is my code, any ideas?

```
tonce = str(int(time.time() * 1e6))

p = 'tonce=' + tonce \
    + '&accesskey=' + self.key \
    + '&requestmethod=post' \
    + '&id=1' \
    + '&method=' + 'getAccountInfo' \
    + '&params='

# Create signature
hmac_obj = hmac.new(self.secret, p, hashlib.sha1)

b64 = 'Basic ' + base64.b64encode(self.key + ':' + hmac_obj.digest())

header = {
    'Json-Rpc-Tonce': tonce,
    'Authorization': b64,
    'content-type': 'application/json-rpc',
}

response = requests.post(self.apiUrl, data=p, headers=header)

```

Am I encrypting and hashing correctly?

**Tags:** api, encryption, hash, authentication, python

> **Comments:**
> **username_1**: What does the returned WWW-Authenticate header say? Is there a body to the response? If so, does it show an error?  
> **username_0**: No body is returned, here is the returned header: {'status': '401 Unauthorized', 'x-request-id': '94f303be4a3e97e8dc289fbe1881555b', 'x-powered-by': 'Phusion Passenger 4.0.14', 'transfer-encoding': 'chunked', 'x-runtime': '0.002153', 'server': 'nginx/1.6.0', 'connection': 'keep-alive', 'x-ua-compatible': 'IE=Edge,chrome=1', 'cache-control': 'no-cache', 'date': 'Thu, 23 Oct 2014 17:18:16 GMT', 'content-type': 'application/json; charset=utf-8', 'x-rack-cache': 'invalidate, pass'}  

---

## 2 answers

### Answer by username_2 on 2014-10-29. Score: 3 | Accepted answer

A closer look at their API page, you will find LakeBTC has provided a simple code for Python: <https://github.com/LakeBTC/lakebtc_python>

And others Sample Code you can find here: <https://www.lakebtc.com/s/api> include PHP, Node.JS, Ruby and Python, maybe will more Code in the future :)

> **Comments:**
> **username_1**: Nice work! I didn't see that on their API page. +1  
> **username_0**: Indeed! I actually just received an email from them after they added it!  

---

### Answer by username_1 on 2014-10-23. Score: 2

I think I figured out your problem. (Or, one of them, at least.)

> Step 6: POST params data in JSON format to this url:  
> <https://www.LakeBTC.com/api_v1>

You're not POSTing the the right information; you're POSTing the entire signature.

```
response = requests.post(self.apiUrl, data=p, headers=header)

```

Should be something along the lines of:

```
response = requests.post(self.apiUrl, data=json.dumps(
    {
        "method": method,
        "params":",".join(params),
        "id": 1,
    }, headers=header)

```


---

