"bitcoinrpc.authproxy.JSONRPCException: -342: non-JSON HTTP response with '401 Unauthorized' from server"
There are many things that can be wrong.  More details are required, like the code you mentioned.
There is a more thorough discussion on this matter here:
https://bitcoin.stackexchange.com/a/106601/113203