0

我想请求在 kubsernets 中显示我的 pod,这个命令对我有用

 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"
    }
  ]

我想在windows上用python写,所以我写了这段代码

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())

在pycharm中运行它后,我得到了这个错误

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'))

如果我在 ubuntu 中运行它,我会得到正确的响应

{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']}

我应该怎么办?

4

0 回答 0