title: bitcoin json rpc with python requests module?
body: <p>I've been trying for hours, and I just don't know what I'm doing wrongly.  It's just for planning/research (not performant) -- playing around with some code from github --  but I need to see it functional.</p>
  
  <pre><code>RPC_USER = username
  RPC_PASS = pasword
  rpc_id =  ID HERE
  jsonrpc = "2.0"
  payload = {"jsonrpc": jsonrpc, "id": rpc_id, "method": method, "params": params}
  authstr = base64.encodestring(bytes('%s:%s' % (RPC_USER, RPC_PASS), 'utf-8')).strip() 
  request_headers = {"Authorization": "Basic %s" % authstr, 'content-type': 'application/json'}
  try:
      response = requests.get(RPC_URL, headers = request_headers, data = json.dumps(payload)).json()
      print(response['result'])      
  except Exception as e: print(str(e))
  if response['id'] != rpc_id:
          raise ValueError("invalid response id!")
  </code></pre>
  
  <p>I get an error as follows:</p>
  
  <p>Here's the whole traceback:</p>
  
  <p><code>Expecting value: line 1 column 1 (char 0)</code> # prints the Exception</p>
  
  <pre><code>Traceback (most recent call last): 
    File "miner_2017.py", line 411, in &lt;module&gt;
      solo_miner(bin2hex("------coinbase message here -----"), "-----bitcoin address here-----")
    File "miner_2017.py", line 401, in solo_miner
      mined_block, hps = block_mine(rpc_getblocktemplate(), coinbase_message, 0, address, timeout=60)
    File "miner_2017.py", line 63, in rpc_getblocktemplate
      try: return rpc("getblocktemplate", [{}])
    File "miner_2017.py", line 52, in rpc
      if response['id'] != rpc_id:
  UnboundLocalError: local variable 'response' referenced before assignment  
  </code></pre>
  
  <p>Which after doing some looking seems to be a problem with decoding the json object from a bytes object rather than a string object.  I don't know how to fix this.  It seems the "response" variable assignment was unsuccessful due to the json problem.  How can I get the json object in string form from the request?</p>
  
  <p>Would somebody help me out? Thanks</p>