简体   繁体   English

使用“请求”来使用比特币地址余额

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

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. 编辑:感谢EdChum的答复。 For anyone wondering how to change a bitcoin balance to satoshis I used this code with the above request- 对于想知道如何将比特币余额更改为satoshis的任何人,我在上面的请求中使用了此代码-

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

You are trying to convert a float value string to int. 您正在尝试将浮点值字符串转换为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

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

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