<p>Indeed to use bitcoinrpc, you need to set the username and password in bitcoin.conf by:</p>
<pre><code>rpcauth=user:salt$hash of password
</code></pre>
<p>which you can generate using <a href="https://github.com/bitcoin/bitcoin/blob/master/share/rpcauth/rpcauth.py" rel="nofollow noreferrer">https://github.com/bitcoin/bitcoin/blob/master/share/rpcauth/rpcauth.py</a>. Simply shutdown bitcoind, add this to bitcoin.conf, restart, and you'll immediately be able to run commands in python like</p>
<pre><code>print(rpc_connection.getinfo())
</code></pre>

CC BY-SA 4.0
2021-02-25T07:12:50.067Z
2021-02-25T07:12:50.067Z
tqd
<p>Tryed to run this code :</p>

<pre><code>from bitcoinrpc.authproxy import AuthServiceProxy, JSONRPCException
import logging
import json

logging.basicConfig()
logging.getLogger("BitcoinRPC").setLevel(logging.DEBUG)

rpc_connection = AuthServiceProxy("http://%s:%s@127.0.0.1:18332"%('user', 'password'))
print(rpc_connection.getinfo())
</code></pre>

<p>with my pass and my username but I have this error:</p>

<p><code>DEBUG:BitcoinRPC:-1-&gt; getinfo []
Traceback (most recent call last):
  File "/home/conio/Scrivania/conioclass/conio/components/provaRPC.py", line 9, in &lt;module&gt;
    print(rpc_connection.getinfo())
  File "/home/conio/Scrivania/conioclass/conio/components/bitcoinrpc/authproxy.py", line 139, in __call__
    response = self._get_response()
  File "/home/conio/Scrivania/conioclass/conio/components/bitcoinrpc/authproxy.py", line 187, in _get_response
    'code': -342, 'message': 'non-JSON HTTP response with \'%i %s\' from server' % (http_response.status, http_response.reason)})
bitcoinrpc.authproxy.JSONRPCException: -342: non-JSON HTTP response with '401 Unauthorized' from server</code></p>

<p>Can you help me?</p>

CC BY-SA 3.0
2016-08-23T12:44:46.120Z
Fixed... there were some problems in the bitcoin.conf file
Antony Zappacosta
<bitcoind><json-rpc><python><rpc-error-25>
I can't connect to RPC from python. JSONRPCException: -342
Antony Zappacosta
# I can't connect to RPC from python. JSONRPCException: -342

(Asked by: username_0 on 2016-08-23)

Tryed to run this code :
from bitcoinrpc.authproxy import AuthServiceProxy, JSONRPCException
import logging
import json

logging.basicConfig()
logging.getLogger("BitcoinRPC").setLevel(logging.DEBUG)

rpc_connection = AuthServiceProxy("http://%s:%s@127.0.0.1:18332"%('user', 'password'))
print(rpc_connection.getinfo())

with my pass and my username but I have this error:
DEBUG:BitcoinRPC:-1-> getinfo []
Traceback (most recent call last):
  File "/home/conio/Scrivania/conioclass/conio/components/provaRPC.py", line 9, in 
    print(rpc_connection.getinfo())
  File "/home/conio/Scrivania/conioclass/conio/components/bitcoinrpc/authproxy.py", line 139, in __call__
    response = self._get_response()
  File "/home/conio/Scrivania/conioclass/conio/components/bitcoinrpc/authproxy.py", line 187, in _get_response
    'code': -342, 'message': 'non-JSON HTTP response with \'%i %s\' from server' % (http_response.status, http_response.reason)})
bitcoinrpc.authproxy.JSONRPCException: -342: non-JSON HTTP response with '401 Unauthorized' from server
Can you help me?

**Tags:** bitcoind, json-rpc, python, rpc-error-25

> **Comments:**
> **username_0**: Fixed... there were some problems in the bitcoin.conf file  

---

## 1 answers

### Answer by username_1 on 2021-02-25. Score: 1

Indeed to use bitcoinrpc, you need to set the username and password in bitcoin.conf by:
rpcauth=user:salt$hash of password

which you can generate using https://github.com/bitcoin/bitcoin/blob/master/share/rpcauth/rpcauth.py. Simply shutdown bitcoind, add this to bitcoin.conf, restart, and you'll immediately be able to run commands in python like
print(rpc_connection.getinfo())


---

