When you say "response 400 error" do you mean 401? If it was a 400 that means you've garbled your url / parameters somehow - although I can't make CH give this response on this endpoint. However it points to the following line having an issue:
re = requests.get(url1,auth=HTTPBasicAuth(keyEncoded,''))
(Aside - I've listed typical error codes from the API towards the end of this post).
Last post from me. I think you should start from basics to prove that your key / IP / network are working together first then go from there. I always start with something like curl (command line) to prove I can get a response at all, then start putting things into code.
Good overview in the following comment / thread (code example is for perl but it's really simple):
There's a checklist for debugging CH on my post on the same thread.
(This also links to two examples in Python).
I was going to ask if you'd checked you were making the requests from a registered IP but I think you should get 403 in this case - see:
If you are using localhost as the server you need to have registered this as above and there's some advice below (end of the thread):
On your examples - I do note that in each example you've posted you've changed several things compared to the last example e.g. changing the key data AND the library you're using which might make it difficult to fix the bug.
Errors / responses
These vary slightly depending on the endpoint but for the company profile endpoint you're calling - which looks OK e.g. just tested that company myself - you should get one of the following:
200 - you should get the data
400 - bad request - unsure how you'd get this for this endpoint (I've just tried) but some others may give you this for incorrect requests.
401 - unauthorised - there's a problem with your API key or the Authorisation header
403 - forbidden - you were trying to access CH from an IP / domain you hadn't registered with CH, or you've been banned
404 - not found - no such company
429 - you exceeded the rate limit.
(Very rarely these days but occasional 5xx responses when there's a server issue).