<p>The issue was that <code>addr</code> is being provided an invalid address - a Main Net address does not work on Test Net, and vice versa.  (From the edit revisions history, the code sample you provided was using <code>bitcoin.wallet.CBitcoinAddress('1JwSSubhmg6iPtRjtyqhUYYH7bZg3Lfy1T')</code> which would provide a Main Net address)</p>

<p>Replace the address being supplied in the <code>addr</code> variable with a legitimate Test Net address, and it should work.</p>

CC BY-SA 3.0
2016-08-09T14:34:10.380Z
The code works. Thanks to @Thoamas Ward for pointing out the mistake
user2065276
CC BY-SA 3.0
2016-08-09T15:19:34.097Z
@ThomasWard Can you explain what does this command do? I am not able to find documentation that explains it well 
addr = bitcoin.wallet.CBitcoinAddress('mfrMeTKojpEXFXpcQiRr7zA3Bff4UBgZTx')
user2065276
CC BY-SA 3.0
2016-08-09T14:47:12.130Z
2016-08-09T14:47:12.130Z
Thomas Ward
<p>When I run the script</p>

<pre><code>from bitcoin.core import COIN, b2lx
import bitcoin.wallet
import bitcoin.rpc

rpc = bitcoin.rpc.Proxy()
addr = bitcoin.wallet.CBitcoinAddress('mfrMeTKojpEXFXpcQiRr7zA3Bff4UBgZTx')

txid = rpc.sendtoaddress(addr, 0.001 * COIN)
print(b2lx(txid))
</code></pre>

<p>I get the following ERROR</p>

<pre><code>CannotSendRequest                         Traceback (most recent call last)
&lt;ipython-input-23-904d1d3102d7&gt; in &lt;module&gt;()
----&gt; 1 txid = rpc.sendtoaddress(addr, 0.001 * COIN)

/home/remote_user/unix_practice/python-bitcoinlib/bitcoin/rpc.py in sendtoaddress(self, addr, amount)
    557         addr = str(addr)
    558         amount = float(amount)/COIN
--&gt; 559         r = self._call('sendtoaddress', addr, amount)
    560         return lx(r)
    561 

/home/remote_user/unix_practice/python-bitcoinlib/bitcoin/rpc.py in _call(self, service_name, *args)
    150                              'User-Agent': DEFAULT_USER_AGENT,
    151                              'Authorization': self.__auth_header,
--&gt; 152                              'Content-type': 'application/json'})
    153 
    154         response = self._get_response()

/usr/lib64/python2.7/httplib.pyc in request(self, method, url, body, headers)
    971     def request(self, method, url, body=None, headers={}):
    972         """Send a complete request to the server."""
--&gt; 973         self._send_request(method, url, body, headers)
    974 
    975     def _set_content_length(self, body):

/usr/lib64/python2.7/httplib.pyc in _send_request(self, method, url, body, headers)
    999             skips['skip_accept_encoding'] = 1
   1000 
-&gt; 1001         self.putrequest(method, url, **skips)
   1002 
   1003         if body is not None and 'content-length' not in header_names:

/usr/lib64/python2.7/httplib.pyc in putrequest(self, method, url, skip_host, skip_accept_encoding)
    869             self.__state = _CS_REQ_STARTED
    870         else:
--&gt; 871             raise CannotSendRequest()
    872 
    873         # Save the method we use, we need it later in the response phase

CannotSendRequest:
</code></pre>

<p>Any idea how to resolve this? I used the code from </p>

<p><a href="https://bitcoin.stackexchange.com/questions/24571/how-to-make-a-simple-payment-with-the-python-bitcoinlib/24661#24661">Sample Post</a></p>

CC BY-SA 3.0
2016-08-09T22:44:43.063Z
If you find an answer especially helpful in solving your problem, you should click the checkmark button next to it to indicate so. Please don't post answers to thank other users, accepting the answer is sufficient.
Murch
<bitcoind><bitcoin-core><python>
cannotsend error using python bitcoin library to send bitcoin on testnet
user2065276
# cannotsend error using python bitcoin library to send bitcoin on testnet

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

When I run the script

```
from bitcoin.core import COIN, b2lx
import bitcoin.wallet
import bitcoin.rpc

rpc = bitcoin.rpc.Proxy()
addr = bitcoin.wallet.CBitcoinAddress('mfrMeTKojpEXFXpcQiRr7zA3Bff4UBgZTx')

txid = rpc.sendtoaddress(addr, 0.001 * COIN)
print(b2lx(txid))

```

I get the following ERROR

```
CannotSendRequest                         Traceback (most recent call last)
<ipython-input-23-904d1d3102d7> in <module>()
----> 1 txid = rpc.sendtoaddress(addr, 0.001 * COIN)

/home/remote_user/unix_practice/python-bitcoinlib/bitcoin/rpc.py in sendtoaddress(self, addr, amount)
    557         addr = str(addr)
    558         amount = float(amount)/COIN
--> 559         r = self._call('sendtoaddress', addr, amount)
    560         return lx(r)
    561 

/home/remote_user/unix_practice/python-bitcoinlib/bitcoin/rpc.py in _call(self, service_name, *args)
    150                              'User-Agent': DEFAULT_USER_AGENT,
    151                              'Authorization': self.__auth_header,
--> 152                              'Content-type': 'application/json'})
    153 
    154         response = self._get_response()

/usr/lib64/python2.7/httplib.pyc in request(self, method, url, body, headers)
    971     def request(self, method, url, body=None, headers={}):
    972         """Send a complete request to the server."""
--> 973         self._send_request(method, url, body, headers)
    974 
    975     def _set_content_length(self, body):

/usr/lib64/python2.7/httplib.pyc in _send_request(self, method, url, body, headers)
    999             skips['skip_accept_encoding'] = 1
   1000 
-> 1001         self.putrequest(method, url, **skips)
   1002 
   1003         if body is not None and 'content-length' not in header_names:

/usr/lib64/python2.7/httplib.pyc in putrequest(self, method, url, skip_host, skip_accept_encoding)
    869             self.__state = _CS_REQ_STARTED
    870         else:
--> 871             raise CannotSendRequest()
    872 
    873         # Save the method we use, we need it later in the response phase

CannotSendRequest:

```

Any idea how to resolve this? I used the code from

[Sample Post](https://bitcoin.stackexchange.com/questions/24571/how-to-make-a-simple-payment-with-the-python-bitcoinlib/24661#24661)

**Tags:** bitcoind, bitcoin-core, python

> **Comments:**
> **username_1**: If you find an answer especially helpful in solving your problem, you should click the checkmark button next to it to indicate so. Please don't post answers to thank other users, accepting the answer is sufficient.  

---

## 1 answers

### Answer by username_2 on 2016-08-09. Score: 1 | Accepted answer

The issue was that `addr` is being provided an invalid address - a Main Net address does not work on Test Net, and vice versa. (From the edit revisions history, the code sample you provided was using `bitcoin.wallet.CBitcoinAddress('1JwSSubhmg6iPtRjtyqhUYYH7bZg3Lfy1T')` which would provide a Main Net address)

Replace the address being supplied in the `addr` variable with a legitimate Test Net address, and it should work.

> **Comments:**
> **username_0**: The code works. Thanks to @Thoamas username_2 for pointing out the mistake  
> **username_0**: @username_2 Can you explain what does this command do? I am not able to find documentation that explains it well  addr = bitcoin.wallet.CBitcoinAddress('mfrMeTKojpEXFXpcQiRr7zA3Bff4UBgZTx')  

---

