Commit 7d72c8b0 authored by Sebastien Robin's avatar Sebastien Robin

do not use httplib directly, use urllib2 instead

It is not recommanded to use httplib directly, we should better
use urllib2, then this library will use httplib. This solve
issues with libnetworkcache when we try to use it behind an
http proxy.
parent 000c1580
......@@ -20,6 +20,7 @@ import json
import os
import tempfile
import urllib
import urllib2
import urlparse
......@@ -45,7 +46,7 @@ class NetworkcacheClient(object):
return_dict['path'] = parsed_url.path
return_dict['host'] = parsed_url.hostname
return_dict['port'] = parsed_url.port
return_dict['port'] = parsed_url.port or 80
return return_dict
def __init__(self, shacache, shadir):
......@@ -145,17 +146,13 @@ class NetworkcacheClient(object):
if directory_key is not None:
path_info = os.path.join(self.shadir_path, directory_key)
shadir_connection = httplib.HTTPConnection(self.shadir_host,
self.shadir_port)
url = "http://%s:%s%s" % (self.shadir_host, self.shadir_port, path_info)
request = urllib2.Request(url=url, data=None,headers=self.shadir_header_dict)
try:
shadir_connection.request('GET', path_info, headers=self.shadir_header_dict)
result = shadir_connection.getresponse()
result = urllib2.urlopen(request)
data = result.read()
finally:
shadir_connection.close()
if result.status != 200:
raise DirectoryNotFound(result.read())
except urllib2.HTTPError, error:
raise DirectoryNotFound("%s : %s" % (error.code, error.msg))
data_list = json.loads(data)
if len(data_list) > 1:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment