urllib2.urlopen表现得很奇怪

时间:2017-07-08 06:06:15

标签: python urllib2 wsgi

我正在使用python 2.7.5。我正在使用urllib2.urlopen()向本地服务器发出客户端请求。当我在我的机器上单独编写这段代码时......它运行顺畅

import json
import urllib2


urls = [ "https://localhost/rest/service1", 
         "https://localhost/rest/service2" ]
for url in urls:
    url_encoded  = urllib2.quote(url, safe="-:?=/")
    token = 'f42fa4d43db94c2782feabf84fa2cc90'
    headers = { "Content-Type": "application/json",
                "X-Auth-Token": token }
    try:
        request = urllib2.Request( url_encoded, headers=headers )
        response = urllib2.urlopen( request )
        reply = response.read()
        data = json.loads(reply)
        print data
    except Exception as ex:
        msg = ex.msg
        print msg

使用WSGI rest框架在我的项目中调用的同一段代码会出现此错误:

-> response = urllib2.urlopen( request )
(Pdb)
URLError: URLError...:579)'),)

请指导我..为什么会这样?

0 个答案:

没有答案
相关问题