使用python获取IOError命中http url

时间:2014-12-16 11:01:42

标签: python jira-rest-api

我尝试点击如下

import urllib
second_query="http://example.com"
pw = urllib.urlopen(second_query)
pw = pw.read()
print pw

我正试图点击jira api - http://example.com,但我收到了错误

Traceback (most recent call last):
      File "abc.py", line 7, in <module>
        pw = urllib.urlopen(second_query)
      File "/abc/xyz/pqr/thirdparty/python/2.6/lib/python2.6/urllib.py", line 87, in urlopen
        return opener.open(url)
      File "/abc/xyz/pqr/thirdparty/python/2.6/lib/python2.6/urllib.py", line 203, in open
        return getattr(self, name)(url)
      File "/abc/xyz/pqr/thirdparty/python/2.6/lib/python2.6/urllib.py", line 358, in open_http
        return self.http_error(url, fp, errcode, errmsg, headers)
      File "/abc/xyz/pqr/thirdparty/python/2.6/lib/python2.6/urllib.py", line 371, in http_error
        result = method(url, fp, errcode, errmsg, headers)
      File "/abc/xyz/pqr/thirdparty/python/2.6/lib/python2.6/urllib.py", line 683, in http_error_401
        errcode, errmsg, headers)
      File "/abc/xyz/pqr/thirdparty/python/2.6/lib/python2.6/urllib.py", line 381, in http_error_default
        raise IOError, ('http error', errcode, errmsg, headers)
    IOError: ('http error', 401, 'Unauthorized', <httplib.HTTPMessage instance at 0x138e26c8>)

请建议解决方案。

3 个答案:

答案 0 :(得分:1)

通过阅读错误,很明显您没有获得所需的授权:

IOError: ('http error', 401, 'Unauthorized', <httplib.HTTPMessage instance at 0x138e26c8>

您已经以某种方式提供必要的凭据......我非常确定Jira提供高级API来使用其工具,因此您不必使用低级方法。

答案 1 :(得分:0)

我不熟悉jira rest API,但是您可能需要提供某种API密钥才能使用它? 401 http状态代码表示您无权执行您尝试执行的操作。

我首先阅读文档:https://docs.atlassian.com/jira/REST/latest(尝试搜索/ rest / auth / 1 / session)

答案 2 :(得分:0)

在您尝试访问主机的示例中,您需要尝试使用完整的网址[{3}}。