0

我尝试连接检查 BTC 地址的数量(使用私钥)。我在文件中有地址和密钥。当我直接编写 var 时,它是 python 脚本,但是当我尝试对文件中的 var 执行相同操作时,它不起作用。从文件中取出它们(使用 print )后,我检查了我的 var,并且我还检查了它们的类型是 String。我也尝试 str() 我的两个 var,但它没有任何改变。我在 windows 上使用 python 3.4 和来自 blockchain.info 的 api。这里是 git 文档:https ://github.com/blockchain/api-v1-client-python/blob/master/docs/wallet.md

sortieFichier = open(fichierSortie, 'a') 
fd = open(fichierClef, 'r')
n = 0
miniCompt=0
aTrouver=": "
for line in fd:
    n += 1
    miniCompt+= 1
    
    #extract the adress from the file
    if(miniCompt==1):
        adressBTC=str(line)
        tronc = adressBTC.find(aTrouver)
        adressBTC =adressBTC[len(aTrouver)+tronc:]
        
     
    if(miniCompt==2):
        # exctract the key
        clefBTC=str(line)
        tronc = clefBTC.find(aTrouver)
        clefBTC =str(clefBTC[len(aTrouver)+tronc:])
         
        print(clefBTC) # = 5J6jgMj4FhcT9y1###########################
        print(adressBTC) # = 1CBXtLZdv4jN9LGF5Dbs##############
        print(isinstance(clefBTC,int)) # return true
         

        # connect with the function to check the wallet 
        wallet = Wallet(clefBTC, '')
        addr = wallet.get_address(adressBTC, confirmations = 2) # Ligne 37 HERE ERROR
        amount=addr.balance
        amount=amount/100000000
        print(amount)
        if(amount>0):
            sortieFichier.write(adressBTC)
            sortieFichier.write(clefBTC)
            sortieFichier.write(amount)
        miniCompt=0
         
         
fd.close()

这里是错误:

True
 
Traceback (most recent call last):
 
  File "C:\Python34\Lib\site-packages\blockchain\monScript.py", line 37, in <mod
 
ule>
 
    addr = wallet.get_address(adressBTC, confirmation
 
s = 2)
 
  File "C:\Python34\lib\site-packages\blockchain\wallet.py", line 133, in get_ad
 
dress
 
    response = util.call_api("merchant/{0}/address_balance".format(self.identifi
 
er), params)
 
  File "C:\Python34\lib\site-packages\blockchain\util.py", line 23, in call_api
 
    response = urlopen(BASE_URL + resource, payload, timeout = TIMEOUT).read()
 
  File "C:\Python34\lib\urllib\request.py", line 153, in urlopen
 
    return opener.open(url, data, timeout)
 
  File "C:\Python34\lib\urllib\request.py", line 453, in open
 
    req = meth(req)
 
  File "C:\Python34\lib\urllib\request.py", line 1097, in do_request_
 
    raise URLError('no host given')
 
urllib.error.URLError: <urlopen error no host given>

这很奇怪,因为如果我写的是密钥/地址而不是 var 它的工作:

wallet = Wallet('5J6jgMj4FhcT9y1###########################', '')
addr = wallet.get_address('1CBXtLZdv4jN9LGF5Dbs##############', confirmations = 2)

我为我糟糕的英语道歉,我仍然愿意接受进一步的解释

4

1 回答 1

0

看不见的字符来这里:adressBTC =adressBTC[len(aTrouver)+tronc:] 因为地址总是相同的大小(同上键)我做:adressBTC =adressBTC[len(aTrouver)+tronc:len(aTrouver)+创+34]

于 2015-03-03T14:33:36.340 回答