I can't connect to RPC from python. JSONRPCException: -342 Tryed to run this code :

from bitcoinrpc.authproxy import AuthServiceProxy, JSONRPCException
import logging
import json

logging.basicConfig()
logging.getLogger("BitcoinRPC").setLevel(logging.DEBUG)

rpc_connection = AuthServiceProxy("http://%s:%s@127.0.0.1:18332"%('user', 'password'))
print(rpc_connection.getinfo())


with my pass and my username but I have this error:

DEBUG:BitcoinRPC:-1-&gt; getinfo []
Traceback (most recent call last):
  File "/home/conio/Scrivania/conioclass/conio/components/provaRPC.py", line 9, in &lt;module&gt;
    print(rpc_connection.getinfo())
  File "/home/conio/Scrivania/conioclass/conio/components/bitcoinrpc/authproxy.py", line 139, in __call__
    response = self._get_response()
  File "/home/conio/Scrivania/conioclass/conio/components/bitcoinrpc/authproxy.py", line 187, in _get_response
    'code': -342, 'message': 'non-JSON HTTP response with \'%i %s\' from server' % (http_response.status, http_response.reason)})
bitcoinrpc.authproxy.JSONRPCException: -342: non-JSON HTTP response with '401 Unauthorized' from server

Can you help me?
Indeed to use bitcoinrpc, you need to set the username and password in bitcoin.conf by:
rpcauth=user:salt$hash of password

which you can generate using https://github.com/bitcoin/bitcoin/blob/master/share/rpcauth/rpcauth.py. Simply shutdown bitcoind, add this to bitcoin.conf, restart, and you'll immediately be able to run commands in python like
print(rpc_connection.getinfo())