在python中的requests.post导致异常

时间:2015-11-17 07:56:03

标签: python

我正在尝试发布以下请求并点击回溯。相同的脚本适用于不同的服务器,但不适用于我的Mac。

代码

url = 'https://172.31.192.28/api/nxosmock/mo/sys/phys-[eth1/30].xml'
xml_data='''
<l1PhysIf adminSt="up" autoNeg="on" bw="0" childAction="" delay="1" descr="" dn="sys/phys-[eth1/30]" dot1qEtherType="0x8100" ethpmCfgFailedBmp="" ethpmCfgFailedTs="00:00:00:00.000" ethpmCfgState="0" id="eth1/30" inhBw="unspecified" layer="Layer2" lcOwn="local" linkDebounce="100" linkLog="default" mdix="auto" medium="broadcast" modTs="2015-11-02T22:53:14.007+00:00" mode="trunk" monPolDn="" mtu="9216" name="" pathSDescr="" portT="unknown" routerMac="not-applicable" snmpTrapSt="enable" spanMode="not-a-span-dest" speed="10G" status="" switchingSt="enabled" trunkLog="default" usage="discovery"/>
#'''
# POST
print 'trying to post interface bringup for SVI'
resp = requests.post(url, data=xml_data, headers=headers, verify=False)
print resp.status_code

点击以下错误

Traceback (most recent call last):
  File "raj-svi-ipv6-interface-bringup-post.py", line 12, in <module>
    resp = requests.post(url, data=xml_data, headers=headers, verify=False)
  File "/Library/Python/2.7/site-packages/requests-2.8.1-py2.7.egg/requests/api.py", line 109, in post
    return request('post', url, data=data, json=json, **kwargs)
  File "/Library/Python/2.7/site-packages/requests-2.8.1-py2.7.egg/requests/api.py", line 50, in request
    response = session.request(method=method, url=url, **kwargs)
  File "/Library/Python/2.7/site-packages/requests-2.8.1-py2.7.egg/requests/sessions.py", line 468, in request
    resp = self.send(prep, **send_kwargs)
  File "/Library/Python/2.7/site-packages/requests-2.8.1-py2.7.egg/requests/sessions.py", line 576, in send
    r = adapter.send(request, **kwargs)
  File "/Library/Python/2.7/site-packages/requests-2.8.1-py2.7.egg/requests/adapters.py", line 412, in send
    raise ConnectionError(err, request=request)
requests.exceptions.ConnectionError: ('Connection aborted.', error(54, 'Connection reset by peer'))

0 个答案:

没有答案