简体   繁体   English

使用Blockchain.info API发送付款-运行时错误:错误:对于输入字符串:“。001”

[英]Send payment using Blockchain.info API - Runtime Error: ERROR: For input string: “.001”

I am trying to send a payment using Blockchain.Info's payment API. 我正在尝试使用Blockchain.Info的付款API发送付款。 I am using a Python libary found on GitHub here: https://github.com/gowness/pyblockchain/blob/master/pyblockchain.py 我正在使用在GitHub上找到的Python库: https : //github.com/gowness/pyblockchain/blob/master/pyblockchain.py

When running the code below I am getting the following error: RuntimeError: ERROR: For input string: ".001" Does anyone know what is going on here? 运行下面的代码时,出现以下错误:RuntimeError:错误:对于输入字符串:“ .001”有人知道这里发生了什么吗? I am running Python 2.7. 我正在运行Python 2.7。 Once I have got the initial sending of one transaction working I would like to look at sending multiple transactions. 最初发送一笔交易后,我想看看发送多笔交易。

from __future__ import print_function
from itertools import islice, imap
import csv, requests, json, math
from collections import defaultdict
import requests
import urllib
import json
from os.path import expanduser
import configparser

class Wallet: 
guid        = 'g'
isAccount   = 0
isKey       = 0
password1   = 'x'
password2   = 'z'
url         = ''

def __init__(self, guid = 'g', password1 = 'x', password2 = 'z'):

    if guid.count('-') > 0:
        self.isAccount = 1
        if password1 == '': # wallet guid's contain - 
            raise ValueError('No password with guid.')
    else:
        self.isKey = 1

    self.guid = guid
    self.url = 'https://blockchain.info/merchant/' + guid + '/'

    self.password1 = password1
    self.password2 = password2

def Call(self, method, data = {}):
    if self.password1 != '':
        data['password'] = self.password1 
    if self.password2 != '':
        data['second_password'] = self.password2

    response = requests.post(self.url + method,params=data)

    json = response.json()
    if 'error' in json:
        raise RuntimeError('ERROR: ' + json['error'])

    return json

def SendPayment(self, toaddr='TA', amount='0.001', fromaddr = 'FA', shared = 0, fee = 0.0001, note = 'test'):
    data = {}
    data['address'] = toaddr
    data['amount'] = amount
    data['fee'] = fee


    if fromaddr != '':
        data['from'] = fromaddr

    if shared == 1:
        data['shared'] = 'true'

    if note != '':
        data['note'] = note

    response = self.Call('payment',data)

    return

def SendManyPayment(self, txs = {} , fromaddr = 'FA', shared = 0, fee = 0.0001, note = 'test'):
    responses = {}

    for tx in txs:
        SendPayment(self, tx[0], tx[1] , fromaddr , shared , fee , note )

    return 



 print(Wallet().SendPayment())

I fixed it, payment amount needed to be in Satoshi not BTC. 我固定了,付款金额必须是Satoshi,而不是BTC。 Should have looked at the API docs a bit more first ;) 应该先看一下API文档;)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM