0
curl -sd '{"inputs":[{"addresses": ["Ee6B32dD1Ca58560831393404891bFDe2fb2efb0"]}],"outputs":[{"addresses": ["a1732BfA2574aEdE9867074131CA1116881fBD5e"], "value":    10000}]}' https://api.blockcypher.com/v1/eth/main/txs/new?token=a893cd1d9d8a4b7284be33376cdcf742

above curl command runs fine in ubuntu bash shell.

But it failed as python with below code.

import requests
url     = 'https://api.blockcypher.com/v1/eth/main/txs/new?token=a893cd1d9d8a4b7284be33376cdcf742'

payload = {
    "inputs":{ 
            "addresses": "Ee6B32dD1Ca58560831393404891bFDe2fb2efb0"
    },
    "outputs":{
            "addresses": "a1732BfA2574aEdE9867074131CA1116881fBD5e", 
            "value":    10000
    }
}


headers = {}
res = requests.post(url, data=payload, headers=headers)
print(res)

result is below.

<Response [400]>

I searched the answer a day but I couldn't find the answer. I tried many ways like pycurl but result was same 400 error.

====================

import requests

url = 'https://api.blockcypher.com/v1/eth/main/txs/new?token=a893cd1d9d8a4b7284be33376cdcf742'

payload = {
    "inputs": {
        "addresses": "Ee6B32dD1Ca58560831393404891bFDe2fb2efb0"
    },
    "outputs": {
        "addresses": "a1732BfA2574aEdE9867074131CA1116881fBD5e",
        "value": 10000
    }
}

headers = {'Content-type': 'application/json'}
res = requests.post(url, json=payload, headers=headers)
print(res)

still gives 400 err...

A5C1D2H2I1M1N2O1R2T1
  • 190,393
  • 28
  • 405
  • 485
  • 1
    Your curl command posts *JSON*, your Python code posts form data. – Martijn Pieters Oct 07 '17 at 17:47
  • I check the previous page tried but result was same. headers = {'Content-type': 'application/json'} . res = requests.post(url, json=payload, headers=headers) – Charlie Kim Oct 08 '17 at 08:27
  • your data structure also doesn't match what curl posts. Both inputs and outputs are lists of objects. – Martijn Pieters Oct 08 '17 at 08:30
  • Since I chaged payload as {"inputs":[{"addresses": ["Ee6B32dD1Ca58560831393404891bFDe2fb2efb0"]}],"outputs":[{"addresses": ["a1732BfA2574aEdE9867074131CA1116881fBD5e"], "value": 10000}]} . it works fine. it was json header and json data format matter. Thank you. – Charlie Kim Oct 08 '17 at 08:50

0 Answers0