簡體   English   中英

使用“請求”來使用比特幣地址余額

[英]Using “requests” to use bitcoin address balance

我正在嘗試獲取比特幣地址的余額並將其用作我的其余應用程序中的數字:

import requests
req = requests.get('http://blockexplorer.com/q/getreceivedbyaddress/19hMEAaRMbEhfSkeU4GT8mgSuyR4t4M6TH/1')

SatoshiConvert = int(req.text) / 100000000
print SatoshiConvert

這導致以下錯誤:

Traceback (most recent call last):
File "checkBalances.py", line 26, in <module>
SatoshiConvert = int(req.text) / 100000000
ValueError: invalid literal for int() with base 10: '83.58000000' 

我認為我試圖將一個對象用作數字,但是盡管嘗試進行轉換,但我一直無法。

編輯:感謝EdChum的答復。 對於想知道如何將比特幣余額更改為satoshis的任何人,我在上面的請求中使用了此代碼-

SatoshiConvert = int((float(req.text))*100000000)

您正在嘗試將浮點值字符串轉換為int。 這為您造成了錯誤。

使用以下代碼,我認為它們是正確的。

import requests
req = requests.get('http://blockexplorer.com/q/getreceivedbyaddress/19hMEAaRMbEhfSkeU4GT8mgSuyR4t4M6TH/1')

SatoshiConvert = float(req.text) / 100000000.0
print SatoshiConvert

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM