1

I am trying to create bill for payment and send to my customer via telegram bot: I am using blockchain API V2-https://blockchain.info/api/api receive .my code is:

xpub='***'
keyk='02e57f1***'
url='https://api.blockchain.info/v2/receive?xpub='+str(xpub)+'&callback=https%3A%2F%2Fdoors03.ru&key='+keyk
x=requests.get(url)
r=x.json()
r=r['address']

r -is an address which was made. I am sending it to my costumer(by the way is there any way to send address with exact sum for pay ) . After I want to check is payment was received:

data={ "Content-Type": "text/plain","key":keyk,"addr":r,"callback":"https%3A%2F%2Fdoors03.ru","onNotification":"KEEP", "op":"RECEIVE"}
r = requests.post(url, data=data)

and this is the response - u'{\n "message" : "Internal handlers error"\n}'

What I am doing wrong? How to check payments? How to send address with exact sum of btc or ethereum?

Jason Aller
  • 3,541
  • 28
  • 38
  • 38
egorkh
  • 478
  • 8
  • 24
  • have you had a look at the blockchain package in pypi? https://pypi.python.org/pypi/blockchain/1.4.0 – pydvlpr Dec 15 '17 at 17:55

1 Answers1

1

Sorry, i don't have enough reputation to post a comment, so this is the only option i have. @egorkh have you solved this problem? Maybe you have received explanation from blockchain.info support? I have sent them a question about that, but they are answering for too long.

UPDATE: Finally, i have found solution.

In my case, reason of "Internal handlers error" message is in a wrong interpretation of their API.

As they haven't implemented balance_update request in their java-api, i did it on my own and i did it in wrong way.

I have put this parameters:

{"key":keyk,"addr":r,"callback":"https%3A%2F%2Fdoors03.ru","onNotification":"KEEP", "op":"RECEIVE"}

as post parameters, like in other methods they have provided in api. In those methods parameters are URLEncoded like you did with callback link. But...

In this HTML request they must be sent as plain text in json format without any special encoding, like that:

Map<String, String> params = new HashMap<String, String>();
    params.put("addr", address);
    params.put("callback", callbackUrl);
    params.put("key", apiCode);
    params.put("onNotification", keepOnNotification? "KEEP" : "DELETE");
    params.put("confs", Integer.toString(confirmationCount));
    params.put("op", StringUtils.isBlank(operationType) ? "ALL" : operationType);
    
//parse parameters map to json string(that's optional: you can write it  directly as string)
String body = new Gson().toJson(params);

if (requestMethod.equals("POST")) {
    byte[] postBytes = body.getBytes("UTF-8");
    conn.setDoOutput(true);
    conn.setRequestProperty("Content-Type", "text/plain");
    conn.setRequestProperty("Content-Length", String.valueOf(postBytes.length));
    conn.getOutputStream().write(postBytes);
    conn.getOutputStream().close();
}

The main reason of your error may be that you put "Content-Type": "text/plain" in data object (, and maybe encoded callback url) .

Community
  • 1
  • 1
diabolusss
  • 29
  • 1
  • 6
  • hi , you can check balance this way https://blockchain.info/rawaddr/1D*** 1D*** - is adress wich you want to check. now i am looking for solution for etherium address . this one not work – egorkh Jan 04 '18 at 12:08
  • i remove content type and paste link without any encode . still the same error ( – egorkh Jan 18 '18 at 18:19
  • @egorkh well, after month of using their api i have found that their servers certainly have problems and support is not the best at helping. I can suggest you to test raw request using [restlet-client extension](https://chrome.google.com/webstore/detail/restlet-client-rest-api-t/aejoelaoggembcahagimdiliamlcdmfm). Just import my [test case](https://pastebin.com/C1hGwNmv) as "Restlet client Repository" and set proper api key and callback. You should receive proper response. – diabolusss Feb 04 '18 at 21:30