petertodd / python-bitcoinlib

Python3 library providing an easy interface to the Bitcoin data structures and protocol.
Other
1.84k stars 624 forks source link

bitcoin.params [bug]? #142

Open cluelessperson opened 7 years ago

cluelessperson commented 7 years ago

root@redwood:/etc/znc/modules# cat test.py

import bitcoin.rpc
txid = '55374e78c86bb739c0ef69f92e3f0cfa9b233e293426170c65a2fe381fd54593'
proxy = **bitcoin.rpc.Proxy(btc_conf_file='/etc/znc/bitcoin.conf')**

root@redwood:/etc/znc/modules# python3.5 test.py

Traceback (most recent call last): File "test.py", line 3, in proxy = bitcoin.rpc.Proxy(btc_conf_file='/etc/znc/bitcoin.conf') File "/usr/local/lib/python3.5/dist-packages/bitcoin/rpc.py", line 302, in init kwargs) File "/usr/local/lib/python3.5/dist-packages/bitcoin/rpc.py", line 157, in init service_port = bitcoin.params.RPC_PORT AttributeError: module 'bitcoin' has no attribute 'params'**


Params is defined here: https://github.com/petertodd/python-bitcoinlib/blob/master/bitcoin/__init__.py#L62 but, bitcoin.rpc DOES contain "import bitcoin" https://github.com/petertodd/python-bitcoinlib/blob/master/bitcoin/rpc.py#L45

adventurist commented 6 years ago

This has been a strange issue for me, as well, affecting me only when doing some tinkering though an interpreter. Does this continue to be an issue for you too?

lgdelgadom commented 6 years ago

Having the same problem on macOS, never had that problem on Ubuntu. Where you able to fix it?

Gillian217 commented 6 years ago

Hi Sir, Im having the same error in ubuntu version 18 from bitcoin.rpc import RawProxy

p= RawProxy() Traceback (most recent call last): File "", line 1, in File "/home/user/.local/lib/python3.6/site-packages/bitcoin/rpc.py", line 288, in init **kwargs) File "/home/user/.local/lib/python3.6/site-packages/bitcoin/rpc.py", line 164, in init service_port = bitcoin.params.RPC_PORT

i've tried to set a service_port but still encounter an issue p= RawProxy(service_port=8332) Traceback (most recent call last): File "", line 1, in File "/home/user/.local/lib/python3.6/site-packages/bitcoin/rpc.py", line 288, in init **kwargs) File "/home/user/.local/lib/python3.6/site-packages/bitcoin/rpc.py", line 172, in init if bitcoin.params.NAME != "mainnet": AttributeError: module 'bitcoin' has no attribute 'params'

Hope you can help me.

lgdelgadom commented 6 years ago

Hi Gillian,

I ended up not using this library, started working directly with bitcoin-qt RPC, it's actually simpler than I thought it would be. You can find the documentation here: https://bitcoin.org/en/developer-reference#remote-procedure-calls-rpcs

Gillian217 commented 6 years ago

Hi sir, Thank you for the quick response, may I ask if you have any idea how to integrate bitcoin-qt in python project?. Sorry I'm just a new in python and bitcoin. Hope you can help me.

lgdelgadom commented 6 years ago

Sure, I'm using the requests library for python. Basically this is the template for every rpc you'll do.

`import requests

url = "http://127.0.0.1:8332" auth = ("user","password") headers = {"Content-type":"text/plain"} data = '{"jsonrpc": "2.0", "method": "getblockcount", "id":"0", "params":[]}'

r = requests.post(url, auth=auth, headers=headers, data=data)`

The response is saved in r, you can get the content with r.text or r.content. This is assuming you are running bitcoind, just change the variables to match your node and the method and parameters for every call you want to make. Hope this helps!

Gillian217 commented 6 years ago

Hi Sir, Thank you for your help. I've tried the command and its working perfectly.

Gillian217 commented 6 years ago

Hi sir, May I ask if you have been connected to testnet of bitcoin?. Because I want to try or test transaction of bitcoin or transfer of bitcoin from one account to another. Hope you could help me.

On Fri, Jun 15, 2018 at 5:22 AM, Luis Gerardo Delgado < notifications@github.com> wrote:

Sure, I'm using the requests library for python. Basically this is the template for every rpc you'll do.

`import requests

url = "http://127.0.0.1:8332" auth = ("user","password") headers = {"Content-type":"text/plain"} data = '{"jsonrpc": "2.0", "method": "getblockcount", "id":"0", "params":[]}'

r = requests.post(url, auth=auth, headers=headers, data=data)`

The response is saved in r, you can get the content with r.text or r.content. This is assuming you are running bitcoind, just change the variables to match your node and the method and parameters for every call you want to make. Hope this helps!

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/petertodd/python-bitcoinlib/issues/142#issuecomment-397442429, or mute the thread https://github.com/notifications/unsubscribe-auth/Aj-CwEuJsuaI07YGPMSj9rcUk6x1M4jUks5t8tQNgaJpZM4O7K9w .

gigimushroom commented 3 years ago

Same error

juxeii commented 2 years ago

Same. Any news on this?

JH6588 commented 2 years ago

I got the same problem on ubuntu 20.04

petertodd commented 2 years ago

I wonder if you guys have a different bitcoin module installed in your PYTHON_PATH?