8

I have Ethereum node running the JSON RPC server on this IP example 136.10.164.134 . Then I want to use a client to push some data. I see this library to make the client.

But I can't connect to my server. I got this error :

requests.exceptions.ConnectionError: HTTPConnectionPool(host='136.10.164.134', port=8545): 
Max retries exceeded with url: / (Caused by NewConnectionError
('<requests.packages.urllib3.connection.HTTPConnection object at 0x10ecfacd0>: 
Failed to establish a new connection: [Errno 61] Connection refused',))

I just put these 3 lines as it's mentioned in the documentation like this in my python script :

from eth_rpc_client import Client
client = Client(host="136.10.164.134", port="8545")
client.get_coinbase()

I think I can't connect to my server because the password itsn't defined in my script. How can I send the server password in ethereum rpc client ?

Edit

Ok So now I fixed the connection problem. I reconfigured parity with this command line :

geth --rpc --rpcaddr <ip> --rpcport <portnumber>

And set my IP to the web3 object :

var Web3 = require('web3');
var web3 = new Web3();
web3.setProvider(new Web3.providers.HttpProvider('http://136.10.164.134:8545'));
web3.eth.syncing

But now I have another problem. I have this error :

ValueError: No JSON object could be decoded

I'm watching the network with Charles and I can see this :

415 Unsupported Media Type
Supplied content type is not allowed. Content-Type: application/json is required

Of course the content-type sent is text/html; charset=utf-8.

How can I change the content type with this Ethererum rpc client ?

  • Possible duplicate of how to unlock the account with geth? – niksmac Nov 23 '16 at 10:07
  • My account is already unclocked. But the problem was the parity configuration. I have to made this command : geth --rpc --rpcaddr <ip> --rpcport <portnumber> and change the web3 ip like this : web3.setProvider(new Web3.providers.HttpProvider('http://136.10.164.134:8545')); instead of local host. But now I have a problem with the content type. – John Nov 23 '16 at 10:40
  • 1
    Can you please post the entire js code? Ethereum clients return only JSON objects. The reason you are getting the error is because you are not treating the response which is a JSON object as a JSON object. – Sebi Nov 23 '16 at 11:32
  • I already paste the whole of my code. I have just these 4 lines. – John Nov 23 '16 at 12:15
  • 2
    @john you should not use ethereum-rpc-client. It's no longer supported. Take a look at web3.py if you want a python option for connecting to an RPC server. – Piper Merriam Nov 24 '16 at 3:09
0

Working solution

Well, as @PiperMerriam said I used this library web3.py. The previous library than I used is no more updated. Now I can connect python web3 to my remote server node like this :

# Import
from web3 import Web3, HTTPProvider

# Connection to the remote server
web3rpc = Web3(HTTPProvider(host="136.10.164.134", port="8545")) 

# Unlock your account
duration = 1000
web3rpc.personal.unlockAccount(web3rpc.eth.coinbase, 'your-passphrase', duration)

# Syncing check
web3rpc.eth.syncing

# Transaction from account A to account B
web3rpc.eth.sendTransaction({'to': 'your_token_account', 'from': web3rpc.eth.coinbase, 'value': web3rpc.toWei(1, "wei"), 'data': web3rpc.toHex('Test Transaction')})

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.