【问题标题】:How to send a request to Coverity web api using urllib2?如何使用 urllib2 向 Coverity Web api 发送请求?
【发布时间】:2015-10-01 10:13:03
【问题描述】:

我正在尝试使用 python/urllib2 向 Coverity Web api 发送 SOAP xml 请求(我无法安装新的 python 模块,因此我的选项仅限于 urllib2)。

下面是我的代码:

def getDateTime():
   t = datetime.now()
   return t.strftime('%Y-%m-%dT%H:%M:%S.%fZ')

def coverityRequest():
    dateAndTime = getDateTime()
    username = 'usernamestr'
    password = 'passstr'
    d = '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:v7="http://ws.coverity.com/v7"> \
    <soapenv:Header><wsse:Security soapenv:mustUnderstand="1" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"><wsse:UsernameToken><wsse:Username>' + username +'</wsse:Username><wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">' + password + '</wsse:Password><wsu:Created>' + dateAndTime + '</wsu:Created></wsse:UsernameToken></wsse:Security></soapenv:Header> \
   <soapenv:Body> \
      <v7:getSnapshotsForStream> \
         <streamId> \
            <name> abc.1.1_ab123 </name> \
         </streamId>  \
         <filterSpec> \
         </filterSpec> \
      </v7:getSnapshotsForStream> \
   </soapenv:Body> \
    </soapenv:Envelope>'

    r = urllib2.Request(url="http://x.x.x.x:8080/ws/v7/configurationservice?wsdl", data=d, headers={'Content-Type': 'text/xml'})
    u = urllib2.urlopen(r)
    response = u.read()
    return response

但是我得到以下输出:

Traceback (most recent call last):
  File "./gen_release_ticket_info.py", line 49, in <module>
    output = coverityRequest()
  File "./gen_release_ticket_info.py", line 44, in coverityRequest
    u = urllib2.urlopen(r)
  File "/usr/lib64/python2.6/urllib2.py", line 126, in urlopen
    return _opener.open(url, data, timeout)
  File "/usr/lib64/python2.6/urllib2.py", line 397, in open
    response = meth(req, response)
  File "/usr/lib64/python2.6/urllib2.py", line 510, in http_response
    'http', request, response, code, msg, hdrs)
  File "/usr/lib64/python2.6/urllib2.py", line 435, in error
    return self._call_chain(*args)
  File "/usr/lib64/python2.6/urllib2.py", line 369, in _call_chain
    result = func(*args)
  File "/usr/lib64/python2.6/urllib2.py", line 518, in http_error_default
    raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
urllib2.HTTPError: HTTP Error 407: Proxy Authorization Required

我 ping 了服务器,它是可以访问的。有什么想法吗?

【问题讨论】:

  • 推送Allow-Origin标头@maduranga-e
  • 你能告诉我在哪里可以了解使用coverity web api吗?

标签: python xml soap urllib2 coverity


【解决方案1】:

该错误代码暗示它正在寻找基本或摘要身份验证。 urllib2 有一个认证接口。 PS 用户名和密码在 d 中未正确编码。如果里面有

【讨论】:

    猜你喜欢
    • 2012-05-07
    • 2021-01-14
    • 1970-01-01
    • 1970-01-01
    • 2016-05-12
    • 2017-12-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多