How to create a request in python insecure by header

5/8/2019

I want to request to show my pods in kubsernets and this command work for me

 curl -X GET https://203.0.113.106:6443/api --header "Authorization: Bearer $TOKEN" --insecure
{
  "kind": "APIVersions",
  "versions": [
    "v1"
  ],
  "serverAddressByClientCIDRs": [
    {
      "clientCIDR": "0.0.0.0/0",
      "serverAddress": "203.0.113.106:6443"
    }
  ]

I want to write it in python on windows so I write this code

import requests

auth_token='eyJhbGciOiJSUzI1NiIsImtpZCI6IiJ9.eyJpc3MiOiJrdWJlcm5ldGVzL3NlcnZpY2VhY2NvdW50Iiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9uYW1lc3BhY2UiOiJkZWZhdWx0Iiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9zZWNyZXQubmFtZSI6ImRlZmF1bHQtdG9rZW4tN2Y2NGYiLCJrdWJlcm5ldGVzLmlvL3NlcnZpY2VhY2NvdW50L3NlcnZpY2UtYWNjb3VudC5uYW1lIjoiZGVmYXVsdCIsImt1YmVybmV0ZXMuaW8vc2VydmljZWFjY291bnQvc2VydmljZS1hY2NvdW50LnVpZCI6IjQ5OThhYzJkLTcwZGMtMTFlOS1hNzQ2LWZhMTYzZTBmNmI5MSIsInN1YiI6InN5c3RlbTpzZXJ2aWNlYWNjb3VudDpkZWZhdWx0OmRlZmF1bHQifQ.nhvHvzSkM_cy84mxra5i12jUNNrsWOf3XSoZtKvMXkIW07Ftto-ce8tr_gceAExbTYdVY5lmhxptHIosevfVCAafceLwE8wN3gXsaguaU8nZjXSR_fX5lFSK5J1s19hfh2vl2lKkb-A2_Yu2j3RdFn70LPL6dRKg9GmJIyIREICe3jq1ZATQj6V9rRjXg1wHc9qdnESmlb5qc9V9_ZJuiT_WbSXwzpgUmwm1YuwajxmV7rbFSFd-TKXsotGIwijoCztxbRRgy_8m_xoinC9UnUtLV-TrRNrSBhuuZe0Wl6ZoItjOSOfMj0NkE5EHPGqqvPjgRcSwMWvUc-pZ6UjoNw'
hed = {'Authorization': 'Bearer ' + auth_token}
url =  'https://203.0.113.106:6443/api'
requests.packages.urllib3.disable_warnings()
response = requests.get(url, headers=hed,verify=False)
print(response)
print(response.json())

After I run it in pycharm I get this error

requests.exceptions.ConnectionError: HTTPSConnectionPool(host='203.0.113.106', port=6443): Max retries exceeded with url: /api (Caused by NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x06152BB0>: Failed to establish a new connection: [WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond'))

And if I run it in ubuntu I get the correct respond

{u'serverAddressByClientCIDRs': [{u'clientCIDR': u'0.0.0.0/0', u'serverAddress': u'203.0.113.106:6443'}], u'kind': u'APIVersions', u'versions': [u'v1']}

What should I do?

-- check nova
docker
kubernetes
kubernetes-python-client
pycharm
python

0 Answers