2015-03-03 39 views
0

我嘗試連接檢查BTC地址的數量(使用私鑰)。 我有一個文件中的地址和密鑰。當我直接寫var時,它是工作的python腳本,但是當我嘗試從var文件執行相同的操作時,它不起作用。我從文件中檢查我的var(打印)後,我也檢查他們的類型是String.I也嘗試str()我的兩個變量,但它沒有改變。我在windows上使用python 3.4,在blockchain.info上使用api。這裏git的文檔:https://github.com/blockchain/api-v1-client-python/blob/master/docs/wallet.md我的var不支持區塊鏈API

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> 

這是非常奇怪的,因爲如果我寫的鍵/ ADRESS而不是VAR它的工作:

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

我爲我的壞英語表示歉意,並且我仍然對進一步的說明持開放態度

回答

0

in可見的字符來這裏:adressBTC = adressBTC [len(aTrouver)+ tronc:] 因此,隨着地址總是相同的大小(鑰匙同性戀)我做的: adressBTC = adressBTC [len(aTrouver)+ tronc:len(aTrouver )+ tronc + 34]