[Ethereum] How to connect Ethereum RPC Client to a remote server

clientsjson-rpcpython

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 ?

Best Answer

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')})
Related Topic