Sunday 28 May 2017

Trouble moving python requests to node.js requests

So I currently have the functioning code in python

import requests
import json
address = "*address here*"
viewkey = "*viewkey here*"
headers = {'content-type': 'application/json'}
url = "https://api.mymonero.com:8443/get_address_txs"

data = {"address":address,"view_key":viewkey}
data = json.dumps(data)


response = requests.post(url, data=data, headers=headers)
print(response.text)

And I tried to move to nodejs to integrate it with another program I have written

var request = require('request');

var options = {
  url: 'https://api.mymonero.com:8443/get_address_txs',
  headers: {'content-type': 'application/json'},
  data: JSON.stringify({
      address:"address",
      viewkey:"viewkey"
  })
};

request.post(options,function(error, response, body) {
  console.log(body);
})

I assumed the code would be identical but clearly not I get an error from the server with the second segment of code. Please could someone help me migrate this?

Note: I know requests in python has a json attribute I have written it in python this way for clarity.

For the record the response I get from the javascript is:

{
  "Error": "Problems parsing JSON"
}

When I get from python:

{
  "total_received": "152840132538",
  "scanned_height": 2589644,
  "scanned_block_height": 1320308,
  "start_height": 2586111,
  ...
}



via Joss Bird

No comments:

Post a Comment