我已经在stackoverflow上看到了同样的问题,但没有找到任何有效的答案:
我使用Requests包连接到CISCO APIC控制器并通过REST API收集json / xml配置;
除了用于连接APIC的密码包括"&"字符;
我拿了一个tcpdump来检查登录时发送的是什么,密码是用"&"正确发送的。包括
以下是用于执行登录的代码提取:
APIC_USER = "admin"
APIC_PW = "azer&tyu"
APIC_IP = 10.1.1.1
login_data = '''<?xml version="1.0" encoding="UTF-8"?>
<imdata totalCount="1">
<aaaUser name="''' + APIC_USER + '''" pwd="''' + APIC_PW + '''"/>
</imdata>'''
APIC_URL = 'http://' + APIC_IP + '/api/'
session = requests.session()
result = session.post(APIC_URL + 'aaaLogin.xml', data=login_data, verify=False)
以下是测试期间的tcpdump输出:
POST /api/aaaLogin.xml HTTP/1.1
Host: 10.1.1.1
Connection: keep-alive
Accept-Encoding: gzip, deflate
Accept: */*
User-Agent: python-requests/2.13.0
Content-Length: 140
<?xml version="1.0" encoding="UTF-8"?>
..<imdata totalCount="1">
..<aaaUser name="admin" pwd="azer&tyu"/>
..</imdata>HTTP/1.1 401 Unauthorized
Server: -/-
Date: Wed, 20 Sep 2017 12:48:21 GMT
Content-Type: application/xml
Content-Length: 129
Connection: keep-alive
感谢您的帮助