I am trying to get the balance of a bitcoin address and use it as a number in the rest of my application:
import requests
req = requests.get('http://blockexplorer.com/q/getreceivedbyaddress/19hMEAaRMbEhfSkeU4GT8mgSuyR4t4M6TH/1')
SatoshiConvert = int(req.text) / 100000000
print SatoshiConvert
This is resulting in the following error:
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'
I think that I am trying to use an object as a number but despite trying to make the transformation, I have been unable to.
EDIT: Thanks to EdChum for the reply. For anyone wondering how to change a bitcoin balance to satoshis I used this code with the above request-
SatoshiConvert = int((float(req.text))*100000000)
You are trying to convert a float value string to int. This has caused the bug for you.
Use the following codes, I think they're right.
import requests
req = requests.get('http://blockexplorer.com/q/getreceivedbyaddress/19hMEAaRMbEhfSkeU4GT8mgSuyR4t4M6TH/1')
SatoshiConvert = float(req.text) / 100000000.0
print SatoshiConvert
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.