<p>I added some code to debug what bitcoin was sending back - it turned out to be a 401 error.</p>

<pre><code>&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd"&gt;
&lt;HTML&gt;
&lt;HEAD&gt;
&lt;TITLE&gt;Error&lt;/TITLE&gt;
&lt;META HTTP-EQUIV='Content-Type' CONTENT='text/html; charset=ISO-8859-1'&gt;
&lt;/HEAD&gt;
&lt;BODY&gt;&lt;H1&gt;401 Unauthorized.&lt;/H1&gt;&lt;/BODY&gt;
&lt;/HTML&gt;
</code></pre>

<p>Why was this triggered? If you look in my bitcoin.conf, and my python code, you can see that the username is different (bitcoinrpc vs. rpcuser). Changing that fixed it.</p>

<p>Anyways, if you get the error <code>ValueError: No JSON object could be decoded</code>, this might be your problem.</p>

CC BY-SA 3.0
2015-03-12T21:45:28.997Z
2015-03-12T21:45:28.997Z
Nick ODell
<p>For anyone else finding this, and the problem was NOT a typo like in the accepted answer:</p>
<p>The issue for me was simply that I had my conf file in the wrong location.</p>
<p>I installed this on Ubuntu 20.04 and saved the conf file in /.bitcoin/bitcoin.conf, but it was looking in /home/user, which was actually ~.bitcoin/bitcoin.conf.</p>
<p>Saving the conf file in the correct location resolved everything.  I could now use bitcoin-cli without sudo, and the python scripts using python-bitcoinrpc.</p>

CC BY-SA 4.0
2021-05-27T06:48:16.917Z
2021-05-27T06:48:16.917Z
coolshoeshine
<p>If you're using the testnet, rpcport should be 18332.</p>

CC BY-SA 3.0
2015-03-13T14:15:05.933Z
It's not required; you just need to use the same ports on both ends. In my bitcoin.conf, I set rpcport to 8332.
Nick ODell
CC BY-SA 3.0
2015-03-15T10:42:03.773Z
@NickODell That would explain my testnet connectivity issues; I didn't realize the conf *rpcport=8332* flag set port 8332 for mainnet *AND* testnet
Wizard Of Ozzie
CC BY-SA 3.0
2015-03-13T10:50:10.167Z
2015-03-13T10:50:10.167Z
sleu
<p>I'm running a testnet node. I can use bitcoin-cli just fine:</p>

<pre><code>&gt;bitcoin-cli.exe getinfo
{
    "version" : 100000,
    "protocolversion" : 70002,
    "walletversion" : 60000,
[... snipped]
</code></pre>

<p>But when I run this python code:</p>

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

rpc_user = "rpcuser"
rpc_password = "xxxxx"

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

rpc_connection = AuthServiceProxy("http://%s:%s@192.168.1.39:8332/" % (rpc_user, rpc_password))
print(rpc_connection.getinfo())
</code></pre>

<p>I get this error:</p>

<pre><code>DEBUG:BitcoinRPC:-1-&gt; getinfo []

Traceback (most recent call last):
  File "&lt;path&gt;\rawtransactiondemo\raw.py", line 11, in &lt;module&gt;
    print(rpc_connection.getinfo())
[... snipped]
  File "C:\Python27\lib\json\decoder.py", line 384, in raw_decode
    raise ValueError("No JSON object could be decoded")
ValueError: No JSON object could be decoded
</code></pre>

<p>This is my bitcoin.conf:</p>

<pre><code>testnet=1
rpcuser=bitcoinrpc
rpcpassword=xxxxx
daemon=1
rpcport=8332
rpcallowip=192.168.1.39
bind=192.168.1.39
</code></pre>

<p>I'm using the <a href="https://github.com/jgarzik/python-bitcoinrpc" rel="nofollow">python-bitcoinrpc</a> library.</p>

<json-rpc><python>
Bitcoin RPC works in bitcoin-cli but not in python-bitcoinrpc: No JSON object
Nick ODell
# Bitcoin RPC works in bitcoin-cli but not in python-bitcoinrpc: No JSON object

(Asked by: username_0 on 2015-03-12)

I'm running a testnet node. I can use bitcoin-cli just fine:

```
>bitcoin-cli.exe getinfo
{
    "version" : 100000,
    "protocolversion" : 70002,
    "walletversion" : 60000,
[... snipped]

```

But when I run this python code:

```
from bitcoinrpc.authproxy import AuthServiceProxy, JSONRPCException
import logging

rpc_user = "rpcuser"
rpc_password = "xxxxx"

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

rpc_connection = AuthServiceProxy("http://%s:%s@192.168.1.39:8332/" % (rpc_user, rpc_password))
print(rpc_connection.getinfo())

```

I get this error:

```
DEBUG:BitcoinRPC:-1-> getinfo []

Traceback (most recent call last):
  File "<path>\rawtransactiondemo\raw.py", line 11, in <module>
    print(rpc_connection.getinfo())
[... snipped]
  File "C:\Python27\lib\json\decoder.py", line 384, in raw_decode
    raise ValueError("No JSON object could be decoded")
ValueError: No JSON object could be decoded

```

This is my bitcoin.conf:

```
testnet=1
rpcuser=bitcoinrpc
rpcpassword=xxxxx
daemon=1
rpcport=8332
rpcallowip=192.168.1.39
bind=192.168.1.39

```

I'm using the [python-bitcoinrpc](https://github.com/jgarzik/python-bitcoinrpc) library.

**Tags:** json-rpc, python


---

## 3 answers

### Answer by username_0 on 2015-03-12. Score: 1 | Accepted answer

I added some code to debug what bitcoin was sending back - it turned out to be a 401 error.

```
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd">
<HTML>
<HEAD>
<TITLE>Error</TITLE>
<META HTTP-EQUIV='Content-Type' CONTENT='text/html; charset=ISO-8859-1'>
</HEAD>
<BODY><H1>401 Unauthorized.</H1></BODY>
</HTML>

```

Why was this triggered? If you look in my bitcoin.conf, and my python code, you can see that the username is different (bitcoinrpc vs. rpcuser). Changing that fixed it.

Anyways, if you get the error `ValueError: No JSON object could be decoded`, this might be your problem.


---

### Answer by username_1 on 2021-05-27. Score: 1

For anyone else finding this, and the problem was NOT a typo like in the accepted answer:

The issue for me was simply that I had my conf file in the wrong location.

I installed this on Ubuntu 20.04 and saved the conf file in /.bitcoin/bitcoin.conf, but it was looking in /home/user, which was actually ~.bitcoin/bitcoin.conf.

Saving the conf file in the correct location resolved everything. I could now use bitcoin-cli without sudo, and the python scripts using python-bitcoinrpc.


---

### Answer by username_2 on 2015-03-13. Score: 0

If you're using the testnet, rpcport should be 18332.

> **Comments:**
> **username_0**: It's not required; you just need to use the same ports on both ends. In my bitcoin.conf, I set rpcport to 8332.  
> **username_3**: @username_0 That would explain my testnet connectivity issues; I didn't realize the conf *rpcport=8332* flag set port 8332 for mainnet *AND* testnet  

---

