donGeilo (OP)
|
|
August 17, 2016, 10:46:46 PM |
|
No, like it is is great i'll give it a try now, just need to figure out how i reach the local host.
Then i'll give you a reply.
But THANK YOU VERY MUCH!!!
|
|
|
|
kaicrypzen
|
|
August 17, 2016, 10:51:47 PM |
|
No, like it is is great i'll give it a try now, just need to figure out how i reach the local host.
Then i'll give you a reply.
But THANK YOU VERY MUCH!!!
Ok then, I can go to sleep . You are very welcome. Good luck .
|
|
|
|
xcbtrader
|
|
August 18, 2016, 07:16:57 AM |
|
Hello If you use a external API like https://blockchain.info/rawaddr/, the problem is if your make more connections to the same IP in a small time, server blockeds your IP (2 o 3 connections per second is max). The solution is add sleep instruction. import time ... ... ... for address in addresses: urlRequest = urllib2.Request("https://blockchain.info/rawaddr/" + address) data = urllib2.urlopen(urlRequest).read() json_data = json.loads(data) balances.append("Balance of " + address + " is " + str(json_data['final_balance'])) time.sleep(0.5) # 2 connectios per second
... ... ...
Another solution is connect differents APIs.
|
|
|
|
donGeilo (OP)
|
|
August 18, 2016, 07:49:42 AM |
|
Yes, thx
that s the reason I want to use my own node.
But unfortunately i can't reach it from the script.
|
|
|
|
kaicrypzen
|
|
August 18, 2016, 08:44:16 AM |
|
Yes, thx
that s the reason I want to use my own node.
But unfortunately i can't reach it from the script.
Still not working? Can you post your code and/or any error/exception you're getting?
|
|
|
|
donGeilo (OP)
|
|
August 18, 2016, 09:00:09 AM Last edit: August 18, 2016, 09:24:45 AM by donGeilo |
|
Good morning! lol No still doesn't work! My code: import urllib2
import json
addresses = open("addresses.txt", "r") balances = open("balances.txt", "w")
for address in addresses: urlRequest = urllib2.Request("http://localhost:3001/insight-api/" + address) data = urllib2.urlopen(urlRequest).read() json_data = json.loads(data) balances.write("Balance of " + address + " is " + str(json_data["data"]["balance"]) + "\n") #use the right keys
addresses.close() balances.close() My errors:
Traceback (most recent call last): File "self4.py", line 10, in <module>
data = urllib2.urlopen(urlRequest).read() File "/usr/lib/python2.7/urllib2.py", line 154, in urlopen return opener.open(url, data, timeout) File "/usr/lib/python2.7/urllib2.py", line 435, in open response = meth(req, response) File "/usr/lib/python2.7/urllib2.py", line 548, in http_response 'http', request, response, code, msg, hdrs) File "/usr/lib/python2.7/urllib2.py", line 473, in error return self._call_chain(*args) File "/usr/lib/python2.7/urllib2.py", line 407, in _call_chain result = func(*args) File "/usr/lib/python2.7/urllib2.py", line 556, in http_error_default raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
urllib2.HTTPError: HTTP Error 404: Not Found
Edit: I think i'm missing something inside the bitcoin.conf file Edtit2: Just recognized, seems to be really close! It's the first time the bitcored-Terminal shows the GET requets from python (but with the 404 error in it). Never appeard before!!!
|
|
|
|
kaicrypzen
|
|
August 18, 2016, 09:51:54 AM |
|
Good morning!
Good morning to you too (or maybe good evening, or good day ) My errors: urllib2.HTTPError: HTTP Error 404: Not Found
If you have this error, then I don't understand why it would work when you enter the url in your browser ... Are you a 100% sure that when you enter http://localhost:3001/insight-api/<address> it works in your browser? You might try two things: - Clean your browser's cache and retry (entering the url directly in the browser). - Add a print statement to see what is actually passed to Request: url = "http://localhost:3001/insight-api/" + address print url
|
|
|
|
donGeilo (OP)
|
|
August 18, 2016, 10:06:14 AM Last edit: August 18, 2016, 10:16:57 AM by donGeilo |
|
Alright, if i put: localhost:3001/insight/ +address in the address-bar i get the error 404! If i just open localhost:3001/insight/ -the page opens an i can put the address in the search field, and it shows me the balance!!! EDIT: I think it supposed to be http://localhost:3001/insight-api/address/ +address 'cause that's the url it shows me if i enter the address in the search field (in fact it shows me"/insight/address/")
|
|
|
|
kaicrypzen
|
|
August 18, 2016, 10:35:10 AM |
|
Alright, if i put: localhost:3001/insight/ +address in the address-bar i get the error 404! If i just open localhost:3001/insight/ -the page opens an i can put the address in the search field, and it shows me the balance!!! EDIT: I think it supposed to be http://localhost:3001/insight-api/address/ +address 'cause that's the url it shows me if i enter the address in the search field (in fact it shows me"/insight/address/") Ah! There might be your answer then. If indeed http://localhost:3001/insight-api/address/<address> is the right url then just update the code and see if it works better
|
|
|
|
donGeilo (OP)
|
|
August 18, 2016, 10:37:35 AM |
|
Nope, same 404 error
|
|
|
|
kaicrypzen
|
|
August 18, 2016, 10:56:58 AM |
|
Nope, same 404 error
Well you'll just have to figure out what the right url is. When you put the address in the search field, do you have to click on a search button (or hit enter) ? If so, then what is the url that appears in the search bar once you've done that? This would be the url you should be using.
|
|
|
|
donGeilo (OP)
|
|
August 18, 2016, 11:05:00 AM |
|
I copy-paste the addres in the search field and hit enter, and the exact url is:
localhost:3001/insight/address/1NH5FzSuo........
but from the bitcore forum i got the info: /insight/* is routed via client-side javascript application, the api is accessible at /insight-api/
|
|
|
|
kaicrypzen
|
|
August 18, 2016, 11:27:32 AM |
|
I copy-paste the addres in the search field and hit enter, and the exact url is:
localhost:3001/insight/address/1NH5FzSuo........
but from the bitcore forum i got the info: /insight/* is routed via client-side javascript application, the api is accessible at /insight-api/
I found this https://github.com/bitpay/insight-apiIt says an address is accessed with: /insight-api/addr/<address> and a balance with: /insight-api/addr/<address>/balance
|
|
|
|
donGeilo (OP)
|
|
August 18, 2016, 11:39:53 AM |
|
If i use: http://localhost:3001/insight-api/addr/+address") http://localhost:3001/insight-api/addr/+address/balance") i get the error 400 bad request EDIT: misstyped in the code!! Now it is just KeyError: 'data' So it passsed the url!!!
|
|
|
|
donGeilo (OP)
|
|
August 18, 2016, 11:44:48 AM |
|
YAY!!! removed 'data'
and ......
it works!!!!!!!!!!!
But gives no output!!!
EDIT:
SOLVED!!!
|
|
|
|
kaicrypzen
|
|
August 18, 2016, 11:53:12 AM |
|
YAY!!! removed 'data'
That's why I commented and ......
it works!!!!!!!!!!!
But gives no output!!!
The code isn't supposed to give any output ... it just stores balances in balances.txt EDIT:
SOLVED!!!
Cool , so what was the matter?
|
|
|
|
kaicrypzen
|
|
August 18, 2016, 12:12:46 PM |
|
during the tests i edited a few balances -output text files
Just looked into the wrong one!
OK Balance of 1NH5FzSuo....... is 0.1
Do you mean there is a carriage return after the address? If that's the case, then use: balances.write("Balance of " + address.strip("\n") + " is " + str(json_data["balance"]) + "\n")
|
|
|
|
donGeilo (OP)
|
|
August 18, 2016, 12:19:01 PM |
|
No everything works fine, like it should!!
Just one more question:
If my list would contain more lines, like:
John Smith Address: 1234567890...
Benjamin Franklin Address: 1098765432.....
How would that look, to just output all balances ?
|
|
|
|
kaicrypzen
|
|
August 18, 2016, 12:47:32 PM |
|
No everything works fine, like it should!!
Just one more question:
If my list would contain more lines, like:
John Smith Address: 1234567890...
Benjamin Franklin Address: 1098765432.....
How would that look, to just output all balances ?
If you have more info in your text file, maybe you should consider using a csv format or make the lines very distinguishable: Name: John Smith Address: 1234567890... Then you'll have to test, let's assume that you don't care about the name: ....
for line in addresses: if line.startswith("Address: "): # Test that the line is an address line address = line.strip("Address: ") # Remove the prefix Address: urlRequest = urllib2.Request("http://localhost:3001/insight-api/addr/" + address) data = urllib2.urlopen(urlRequest).read() json_data = json.loads(data) balances.write("Balance of " + address + " is " + str(json_data["balance"]) + "\n")
....
|
|
|
|
donGeilo (OP)
|
|
August 18, 2016, 01:18:39 PM |
|
Perfect!!!
Thanks alot!!!
|
|
|
|
|