Python AWS身份验证使用HTTPS请求失败
我正在AWS的EC2实例上部署CSR1000V 这是用于身份验证的python代码,以便使用路由器中已启用的RESTCONFPython AWS身份验证使用HTTPS请求失败,python,amazon-web-services,amazon-ec2,cisco,ietf-restconf,Python,Amazon Web Services,Amazon Ec2,Cisco,Ietf Restconf,我正在AWS的EC2实例上部署CSR1000V 这是用于身份验证的python代码,以便使用路由器中已启用的RESTCONF import requests import pprint from aws_requests_auth.aws_auth import AWSRequestsAuth def get_json(interface): authaws = AWSRequestsAuth(aws_access_key='AWS_ACCESS_KEY',
import requests
import pprint
from aws_requests_auth.aws_auth import AWSRequestsAuth
def get_json(interface):
authaws = AWSRequestsAuth(aws_access_key='AWS_ACCESS_KEY',
aws_secret_access_key='AWS_SECRET_ACCESS_KEY',
aws_host='ec2-xx-xx-xx-xx.us-west-2.compute.amazonaws.com',
aws_region='us-west-2',
aws_service='compute')
source = 'https://ec2-xx-xx-xx-xx.us-west-2.compute.amazonaws.com/restconf/data/'
module = 'ietf-interfaces:'
container = 'interfaces'
leaf = '/interface=' + interface
options = ''
url = source + module + container + leaf + options
headers = {'Content-type': 'application/yang-data+json', 'Accept': 'application/yang-data+json'}
r = requests.get(url, auth=authaws, headers=headers, verify=False)
return r.json()
if __name__ == '__main__':
interface = 'GigabitEthernet1'
pprint.pprint(get_json(interface))
这是我被处决后得到的
server@zsz:~/shared_files$ python get_one_interface.py
/usr/local/lib/python2.7/dist-packages/urllib3/connectionpool.py:847: InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
InsecureRequestWarning)
{u'errors': {u'error': [{u'error-tag': u'access-denied',
u'error-type': u'protocol'}]}}
显然,身份验证无法完成。
对于
aws\u access\u key
和aws\u secret\u access\u key
,我是从IAM控制台获得的。我甚至生成了新的,但仍然不起作用。我已经设法找到了解决方案
在路由器中:
(config)#user any-user-name privilege 15 secret supersecretpassword
然后,它成功了!
感谢所有试图提供帮助的人:)第一个问题似乎与SSL证书验证有关,因此您应该对此进行调查。证书验证显然是安全通信中防止MITM攻击的重要功能。相关:@jarmod已解决与SSL证书验证相关的问题。然而,错误仍然存在<代码>{u'errors':{u'error':[{u'error-tag':u'access-denied',u'error-type':u'protocol'}]}}我不熟悉restconf,但您确定AWS凭据在这里确实有效吗?它们是针对AWS服务进行身份验证的凭据。@嗯,HTTP(S)流量是允许的。否则,我不知道如何检查凭据以进行身份验证。我认为这是这里的主要问题。我认为最好能更多地了解与netconf的交互以及您在EC2实例上安装的netconf服务器的身份验证要求。您可能需要从ncclient包使用manager,使用nc特定身份验证连接到netconf管理器,然后从那里检索功能。看见