Skip to content

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also .

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also .
...
Checking mergeability… Don’t worry, you can still create the pull request.
  • 15 commits
  • 23 files changed
  • 3 commit comments
  • 2 contributors
Commits on Feb 04, 2012
@gtaylor gtaylor Initial work to replace httplib/urllib with requests. Lots broken, bu…
…t a good bit works.
836ba65
Commits on Feb 05, 2012
@gtaylor gtaylor Fixing some S3 tests, adding more debugging. ff6cd97
@gtaylor gtaylor Fix and document s3.key.Key.read(). 0b1a943
@gtaylor gtaylor Fixing boto.s3.key.Key.get_file(). Also fixes the various Key.get_con…
…tents_* methods.
bc885c3
@gtaylor gtaylor Correcting the reading of response headers in CloudFrontConnection. 135e361
@gtaylor gtaylor PEP8'ification of s3 submodule. 35aba6b
Commits on Feb 06, 2012
@gtaylor gtaylor No longer need threading in boto.connection. Connection pooling is no…
…w handled by requests.
0e09992
@gtaylor gtaylor boto.connection no longer needs base64 or urllib, either. 46ca615
@gtaylor gtaylor Changing the boto.connection logging to show request headers more acc…
…urately. Also re-formatted logging to add some blank lines between request/response, for easier reading.
e381b2e
Commits on Feb 07, 2012
@gtaylor gtaylor Merge branch 'master' into requests_refactor 8803fc5
@garnaat garnaat More debug output and adding explicit content-types to all S3 PUT's t…
…o make requests happy.
236c016
Commits on Feb 08, 2012
@gtaylor gtaylor Merge remote-tracking branch 'origin/master' into requests_refactor 584e136
@gtaylor gtaylor Merge branch 'master' into requests_refactor b7cb53b
@garnaat garnaat Merging conflict in bucket.py e392074
Commits on Feb 23, 2012
@garnaat garnaat Merging from master, resolving conflict in s3/key.py. Considerably mo…
…re work is required here.
e19270e
View
40 boto/cloudformation/connection.py
@@ -133,14 +133,14 @@ def create_stack(self, stack_name, template_body=None, template_url=None,
params['TimeoutInMinutes'] = int(timeout_in_minutes)
response = self.make_request('CreateStack', params, '/', 'POST')
- body = response.read()
- if response.status == 200:
+ body = response.content
+ if response.status_code == 200:
body = json.loads(body)
return body['CreateStackResponse']['CreateStackResult']['StackId']
else:
- boto.log.error('%s %s' % (response.status, response.reason))
+ boto.log.error('%s %s' % (response.status_code, response.reason))
boto.log.error('%s' % body)
- raise self.ResponseError(response.status, response.reason, body)
+ raise self.ResponseError(response.status_code, response.reason, body)
def update_stack(self, stack_name, template_body=None, template_url=None,
parameters=[], notification_arns=[], disable_rollback=False,
@@ -200,26 +200,26 @@ def update_stack(self, stack_name, template_body=None, template_url=None,
params['TimeoutInMinutes'] = int(timeout_in_minutes)
response = self.make_request('UpdateStack', params, '/', 'POST')
- body = response.read()
- if response.status == 200:
+ body = response.content
+ if response.status_code == 200:
body = json.loads(body)
return body['UpdateStackResponse']['UpdateStackResult']['StackId']
else:
- boto.log.error('%s %s' % (response.status, response.reason))
+ boto.log.error('%s %s' % (response.status_code, response.reason))
boto.log.error('%s' % body)
- raise self.ResponseError(response.status, response.reason, body)
+ raise self.ResponseError(response.status_code, response.reason, body)
def delete_stack(self, stack_name_or_id):
params = {'ContentType': "JSON", 'StackName': stack_name_or_id}
# TODO: change this to get_status ?
response = self.make_request('DeleteStack', params, '/', 'GET')
- body = response.read()
- if response.status == 200:
+ body = response.content
+ if response.status_code == 200:
return json.loads(body)
else:
- boto.log.error('%s %s' % (response.status, response.reason))
+ boto.log.error('%s %s' % (response.status_code, response.reason))
boto.log.error('%s' % body)
- raise self.ResponseError(response.status, response.reason, body)
+ raise self.ResponseError(response.status_code, response.reason, body)
def describe_stack_events(self, stack_name_or_id=None, next_token=None):
params = {}
@@ -235,13 +235,13 @@ def describe_stack_resource(self, stack_name_or_id, logical_resource_id):
'LogicalResourceId': logical_resource_id}
response = self.make_request('DescribeStackResource', params,
'/', 'GET')
- body = response.read()
- if response.status == 200:
+ body = response.content
+ if response.status_code == 200:
return json.loads(body)
else:
- boto.log.error('%s %s' % (response.status, response.reason))
+ boto.log.error('%s %s' % (response.status_code, response.reason))
boto.log.error('%s' % body)
- raise self.ResponseError(response.status, response.reason, body)
+ raise self.ResponseError(response.status_code, response.reason, body)
def describe_stack_resources(self, stack_name_or_id=None,
logical_resource_id=None,
@@ -265,13 +265,13 @@ def describe_stacks(self, stack_name_or_id=None):
def get_template(self, stack_name_or_id):
params = {'ContentType': "JSON", 'StackName': stack_name_or_id}
response = self.make_request('GetTemplate', params, '/', 'GET')
- body = response.read()
- if response.status == 200:
+ body = response.content
+ if response.status_code == 200:
return json.loads(body)
else:
- boto.log.error('%s %s' % (response.status, response.reason))
+ boto.log.error('%s %s' % (response.status_code, response.reason))
boto.log.error('%s' % body)
- raise self.ResponseError(response.status, response.reason, body)
+ raise self.ResponseError(response.status_code, response.reason, body)
def list_stack_resources(self, stack_name_or_id, next_token=None):
params = {'StackName': stack_name_or_id}
View
52 boto/cloudfront/__init__.py
@@ -47,7 +47,7 @@ def __init__(self, aws_access_key_id=None, aws_secret_access_key=None,
True, port, proxy, proxy_port, debug=debug)
def get_etag(self, response):
- response_headers = response.msg
+ response_headers = response.headers
for key in response_headers.keys():
if key.lower() == 'etag':
return response_headers[key]
@@ -62,10 +62,10 @@ def _get_all_objects(self, resource, tags):
if not tags:
tags=[('DistributionSummary', DistributionSummary)]
response = self.make_request('GET', '/%s/%s' % (self.Version, resource))
- body = response.read()
+ body = response.content
boto.log.debug(body)
- if response.status >= 300:
- raise CloudFrontServerError(response.status, response.reason, body)
+ if response.status_code >= 300:
+ raise CloudFrontServerError(response.status_code, response.reason, body)
rs = ResultSet(tags)
h = handler.XmlHandler(rs, self)
xml.sax.parseString(body, h)
@@ -74,12 +74,12 @@ def _get_all_objects(self, resource, tags):
def _get_info(self, id, resource, dist_class):
uri = '/%s/%s/%s' % (self.Version, resource, id)
response = self.make_request('GET', uri)
- body = response.read()
+ body = response.content
boto.log.debug(body)
- if response.status >= 300:
- raise CloudFrontServerError(response.status, response.reason, body)
+ if response.status_code >= 300:
+ raise CloudFrontServerError(response.status_code, response.reason, body)
d = dist_class(connection=self)
- response_headers = response.msg
+ response_headers = response.headers
for key in response_headers.keys():
if key.lower() == 'etag':
d.etag = response_headers[key]
@@ -90,10 +90,10 @@ def _get_info(self, id, resource, dist_class):
def _get_config(self, id, resource, config_class):
uri = '/%s/%s/%s/config' % (self.Version, resource, id)
response = self.make_request('GET', uri)
- body = response.read()
+ body = response.content
boto.log.debug(body)
- if response.status >= 300:
- raise CloudFrontServerError(response.status, response.reason, body)
+ if response.status_code >= 300:
+ raise CloudFrontServerError(response.status_code, response.reason, body)
d = config_class(connection=self)
d.etag = self.get_etag(response)
h = handler.XmlHandler(d, self)
@@ -108,33 +108,33 @@ def _set_config(self, distribution_id, etag, config):
uri = '/%s/%s/%s/config' % (self.Version, resource, distribution_id)
headers = {'If-Match' : etag, 'Content-Type' : 'text/xml'}
response = self.make_request('PUT', uri, headers, config.to_xml())
- body = response.read()
+ body = response.content
boto.log.debug(body)
- if response.status != 200:
- raise CloudFrontServerError(response.status, response.reason, body)
+ if response.status_code != 200:
+ raise CloudFrontServerError(response.status_code, response.reason, body)
return self.get_etag(response)
def _create_object(self, config, resource, dist_class):
response = self.make_request('POST', '/%s/%s' % (self.Version, resource),
{'Content-Type' : 'text/xml'}, data=config.to_xml())
- body = response.read()
+ body = response.content
boto.log.debug(body)
- if response.status == 201:
+ if response.status_code == 201:
d = dist_class(connection=self)
h = handler.XmlHandler(d, self)
xml.sax.parseString(body, h)
d.etag = self.get_etag(response)
return d
else:
- raise CloudFrontServerError(response.status, response.reason, body)
+ raise CloudFrontServerError(response.status_code, response.reason, body)
def _delete_object(self, id, etag, resource):
uri = '/%s/%s/%s' % (self.Version, resource, id)
response = self.make_request('DELETE', uri, {'If-Match' : etag})
- body = response.read()
+ body = response.content
boto.log.debug(body)
- if response.status != 204:
- raise CloudFrontServerError(response.status, response.reason, body)
+ if response.status_code != 204:
+ raise CloudFrontServerError(response.status_code, response.reason, body)
# Distributions
@@ -241,24 +241,24 @@ def create_invalidation_request(self, distribution_id, paths,
response = self.make_request('POST', uri,
{'Content-Type' : 'text/xml'},
data=paths.to_xml())
- body = response.read()
- if response.status == 201:
+ body = response.content
+ if response.status_code == 201:
h = handler.XmlHandler(paths, self)
xml.sax.parseString(body, h)
return paths
else:
- raise CloudFrontServerError(response.status, response.reason, body)
+ raise CloudFrontServerError(response.status_code, response.reason, body)
def invalidation_request_status (self, distribution_id, request_id, caller_reference=None):
uri = '/%s/distribution/%s/invalidation/%s' % (self.Version, distribution_id, request_id )
response = self.make_request('GET', uri, {'Content-Type' : 'text/xml'})
- body = response.read()
- if response.status == 200:
+ body = response.content
+ if response.status_code == 200:
paths = InvalidationBatch([])
h = handler.XmlHandler(paths, self)
xml.sax.parseString(body, h)
return paths
else:
- raise CloudFrontServerError(response.status, response.reason, body)
+ raise CloudFrontServerError(response.status_code, response.reason, body)
View
580 boto/connection.py
@@ -43,7 +43,6 @@
"""
from __future__ import with_statement
-import base64
import errno
import httplib
import os
@@ -53,9 +52,11 @@
import socket
import sys
import time
-import urllib, urlparse
+import urlparse
import xml.sax
+import requests
+
import auth
import auth_handler
import boto
@@ -78,10 +79,51 @@
except ImportError:
pass
-try:
- import threading
-except ImportError:
- import dummy_threading as threading
+# This is an ugly hack to bring over the sillyness that is HTTPResponse.reason.
+# TODO: Try to get this from somewhere else? Can we pluck straight from
+# httplib? Didn't have time to source dive.
+HTTP_REASON_CODES = {
+ "100": "Continue",
+ "101": "Switching Protocols",
+ "200": "OK",
+ "201": "Created",
+ "202": "Accepted",
+ "203": "Non-Authoritative Information",
+ "204": "No Content",
+ "205": "Reset Content",
+ "206": "Partial Content",
+ "300": "Multiple Choices",
+ "301": "Moved Permanently",
+ "302": "Found",
+ "303": "See Other",
+ "304": "Not Modified",
+ "305": "Use Proxy",
+ "307": "Temporary Redirect",
+ "400": "Bad Request",
+ "401": "Unauthorized",
+ "402": "Payment Required",
+ "403": "Forbidden",
+ "404": "Not Found",
+ "405": "Method Not Allowed",
+ "406": "Not Acceptable",
+ "407": "Proxy Authentication Required",
+ "408": "Request Time-out",
+ "409": "Conflict",
+ "410": "Gone",
+ "411": "Length Required",
+ "412": "Precondition Failed",
+ "413": "Request Entity Too Large",
+ "414": "Request-URI Too Large",
+ "415": "Unsupported Media Type",
+ "416": "Requested range not satisfiable",
+ "417": "Expectation Failed",
+ "500": "Internal Server Error",
+ "501": "Not Implemented",
+ "502": "Bad Gateway",
+ "503": "Service Unavailable",
+ "504": "Gateway Time-out",
+ "505": "HTTP Version not supported",
+}
ON_APP_ENGINE = all(key in os.environ for key in (
'USER_IS_ADMIN', 'CURRENT_VERSION_ID', 'APPLICATION_ID'))
@@ -91,201 +133,12 @@
DEFAULT_CA_CERTS_FILE = os.path.join(
os.path.dirname(os.path.abspath(boto.cacerts.__file__ )), "cacerts.txt")
-class HostConnectionPool(object):
-
- """
- A pool of connections for one remote (host,is_secure).
-
- When connections are added to the pool, they are put into a
- pending queue. The _mexe method returns connections to the pool
- before the response body has been read, so they connections aren't
- ready to send another request yet. They stay in the pending queue
- until they are ready for another request, at which point they are
- returned to the pool of ready connections.
-
- The pool of ready connections is an ordered list of
- (connection,time) pairs, where the time is the time the connection
- was returned from _mexe. After a certain period of time,
- connections are considered stale, and discarded rather than being
- reused. This saves having to wait for the connection to time out
- if AWS has decided to close it on the other end because of
- inactivity.
-
- Thread Safety:
-
- This class is used only fram ConnectionPool while it's mutex
- is held.
- """
-
- def __init__(self):
- self.queue = []
-
- def size(self):
- """
- Returns the number of connections in the pool for this host.
- Some of the connections may still be in use, and may not be
- ready to be returned by get().
- """
- return len(self.queue)
-
- def put(self, conn):
- """
- Adds a connection to the pool, along with the time it was
- added.
- """
- self.queue.append((conn, time.time()))
-
- def get(self):
- """
- Returns the next connection in this pool that is ready to be
- reused. Returns None of there aren't any.
- """
- # Discard ready connections that are too old.
- self.clean()
-
- # Return the first connection that is ready, and remove it
- # from the queue. Connections that aren't ready are returned
- # to the end of the queue with an updated time, on the
- # assumption that somebody is actively reading the response.
- for _ in range(len(self.queue)):
- (conn, _) = self.queue.pop(0)
- if self._conn_ready(conn):
- return conn
- else:
- self.put(conn)
- return None
-
- def _conn_ready(self, conn):
- """
- There is a nice state diagram at the top of httplib.py. It
- indicates that once the response headers have been read (which
- _mexe does before adding the connection to the pool), a
- response is attached to the connection, and it stays there
- until it's done reading. This isn't entirely true: even after
- the client is done reading, the response may be closed, but
- not removed from the connection yet.
-
- This is ugly, reading a private instance variable, but the
- state we care about isn't available in any public methods.
- """
- if ON_APP_ENGINE:
- # Google App Engine implementation of HTTPConnection doesn't contain
- # _HTTPConnection__response attribute. Moreover, it's not possible
- # to determine if given connection is ready. Reusing connections
- # simply doesn't make sense with App Engine urlfetch service.
- return False
- else:
- response = getattr(conn, '_HTTPConnection__response', None)
- return (response is None) or response.isclosed()
-
- def clean(self):
- """
- Get rid of stale connections.
- """
- # Note that we do not close the connection here -- somebody
- # may still be reading from it.
- while len(self.queue) > 0 and self._pair_stale(self.queue[0]):
- self.queue.pop(0)
-
- def _pair_stale(self, pair):
- """
- Returns true of the (connection,time) pair is too old to be
- used.
- """
- (_conn, return_time) = pair
- now = time.time()
- return return_time + ConnectionPool.STALE_DURATION < now
-
-class ConnectionPool(object):
-
+class HTTPRequest(object):
"""
- A connection pool that expires connections after a fixed period of
- time. This saves time spent waiting for a connection that AWS has
- timed out on the other end.
-
- This class is thread-safe.
+ A data encapsulation class used for passing values to our HTTP client.
+ This is currently the 'requests' library.
"""
- #
- # The amout of time between calls to clean.
- #
-
- CLEAN_INTERVAL = 5.0
-
- #
- # How long before a connection becomes "stale" and won't be reused
- # again. The intention is that this time is less that the timeout
- # period that AWS uses, so we'll never try to reuse a connection
- # and find that AWS is timing it out.
- #
- # Experimentation in July 2011 shows that AWS starts timing things
- # out after three minutes. The 60 seconds here is conservative so
- # we should never hit that 3-minute timout.
- #
-
- STALE_DURATION = 60.0
-
- def __init__(self):
- # Mapping from (host,is_secure) to HostConnectionPool.
- # If a pool becomes empty, it is removed.
- self.host_to_pool = {}
- # The last time the pool was cleaned.
- self.last_clean_time = 0.0
- self.mutex = threading.Lock()
-
- def size(self):
- """
- Returns the number of connections in the pool.
- """
- return sum(pool.size() for pool in self.host_to_pool.values())
-
- def get_http_connection(self, host, is_secure):
- """
- Gets a connection from the pool for the named host. Returns
- None if there is no connection that can be reused. It's the caller's
- responsibility to call close() on the connection when it's no longer
- needed.
- """
- self.clean()
- with self.mutex:
- key = (host, is_secure)
- if key not in self.host_to_pool:
- return None
- return self.host_to_pool[key].get()
-
- def put_http_connection(self, host, is_secure, conn):
- """
- Adds a connection to the pool of connections that can be
- reused for the named host.
- """
- with self.mutex:
- key = (host, is_secure)
- if key not in self.host_to_pool:
- self.host_to_pool[key] = HostConnectionPool()
- self.host_to_pool[key].put(conn)
-
- def clean(self):
- """
- Clean up the stale connections in all of the pools, and then
- get rid of empty pools. Pools clean themselves every time a
- connection is fetched; this cleaning takes care of pools that
- aren't being used any more, so nothing is being gotten from
- them.
- """
- with self.mutex:
- now = time.time()
- if self.last_clean_time + self.CLEAN_INTERVAL < now:
- to_remove = []
- for (host, pool) in self.host_to_pool.items():
- pool.clean()
- if pool.size() == 0:
- to_remove.append(host)
- for host in to_remove:
- del self.host_to_pool[host]
- self.last_clean_time = now
-
-class HTTPRequest(object):
-
def __init__(self, method, protocol, host, port, path, auth_path,
params, headers, body):
"""Represents an HTTP request.
@@ -327,32 +180,26 @@ def __init__(self, method, protocol, host, port, path, auth_path,
self.host = host
self.port = port
self.path = path
- if auth_path is None:
- auth_path = path
- self.auth_path = auth_path
+ self.auth_path = auth_path or path
self.params = params
+ self.body = body
+
# chunked Transfer-Encoding should act only on PUT request.
if headers and 'Transfer-Encoding' in headers and \
- headers['Transfer-Encoding'] == 'chunked' and \
- self.method != 'PUT':
+ headers['Transfer-Encoding'] == 'chunked' and \
+ self.method != 'PUT':
self.headers = headers.copy()
del self.headers['Transfer-Encoding']
else:
self.headers = headers
- self.body = body
def __str__(self):
return (('method:(%s) protocol:(%s) host(%s) port(%s) path(%s) '
- 'params(%s) headers(%s) body(%s)') % (self.method,
- self.protocol, self.host, self.port, self.path, self.params,
- self.headers, self.body))
+ 'params(%s) headers(%s) body(%s)') % (
+ self.method, self.protocol, self.host, self.port, self.path,
+ self.params, self.headers, self.body))
def authorize(self, connection, **kwargs):
- for key in self.headers:
- val = self.headers[key]
- if isinstance(val, unicode):
- self.headers[key] = urllib.quote_plus(val.encode('utf-8'))
-
connection._auth_handler.add_auth(self, **kwargs)
self.headers['User-Agent'] = UserAgent
@@ -427,15 +274,18 @@ def __init__(self, host, aws_access_key_id=None, aws_secret_access_key=None,
"2.6 or later.")
self.ca_certificates_file = config.get_value(
'Boto', 'ca_certificates_file', DEFAULT_CA_CERTS_FILE)
- self.handle_proxy(proxy, proxy_port, proxy_user, proxy_pass)
# define exceptions from httplib that we want to catch and retry
- self.http_exceptions = (httplib.HTTPException, socket.error,
- socket.gaierror)
+ # TODO: Update for requests.
+ self.http_exceptions = (
+ httplib.HTTPException,
+ socket.error,
+ socket.gaierror
+ )
# define subclasses of the above that are not retryable.
self.http_unretryable_exceptions = []
if HAVE_HTTPS_CONNECTION:
self.http_unretryable_exceptions.append(
- https_connection.InvalidCertificateException)
+ requests.exceptions.SSLError)
# define values in socket exceptions we don't want to catch
self.socket_exception_values = (errno.EINTR,)
@@ -444,7 +294,7 @@ def __init__(self, host, aws_access_key_id=None, aws_secret_access_key=None,
self.http_exceptions += https_connection_factory[1]
else:
self.https_connection_factory = None
- if (is_secure):
+ if is_secure:
self.protocol = 'https'
else:
self.protocol = 'http'
@@ -459,16 +309,10 @@ def __init__(self, host, aws_access_key_id=None, aws_secret_access_key=None,
else:
self.port = PORTS_BY_SECURITY[is_secure]
- # Timeout used to tell httplib how long to wait for socket timeouts.
- # Default is to leave timeout unchanged, which will in turn result in
- # the socket's default global timeout being used. To specify a
- # timeout, set http_socket_timeout in Boto config. Regardless,
- # timeouts will only be applied if Python is 2.6 or greater.
- self.http_connection_kwargs = {}
- if (sys.version_info[0], sys.version_info[1]) >= (2, 6):
- if config.has_option('Boto', 'http_socket_timeout'):
- timeout = config.getint('Boto', 'http_socket_timeout')
- self.http_connection_kwargs['timeout'] = timeout
+ if config.has_option('Boto', 'http_socket_timeout'):
+ self.timeout = config.getint('Boto', 'http_socket_timeout')
+ else:
+ self.timeout = None
self.provider = Provider(provider,
aws_access_key_id,
@@ -479,7 +323,6 @@ def __init__(self, host, aws_access_key_id=None, aws_secret_access_key=None,
if self.provider.host:
self.host = self.provider.host
- self._pool = ConnectionPool()
self._connection = (self.server_name(), self.is_secure)
self._last_rs = None
self._auth_handler = auth.get_auth_handler(
@@ -491,10 +334,6 @@ def __repr__(self):
def _required_auth_capability(self):
return []
- def connection(self):
- return self.get_http_connection(*self._connection)
- connection = property(connection)
-
def aws_access_key_id(self):
return self.provider.access_key
aws_access_key_id = property(aws_access_key_id)
@@ -554,148 +393,6 @@ def server_name(self, port=None):
signature_host = '%s:%d' % (self.host, port)
return signature_host
- def handle_proxy(self, proxy, proxy_port, proxy_user, proxy_pass):
- self.proxy = proxy
- self.proxy_port = proxy_port
- self.proxy_user = proxy_user
- self.proxy_pass = proxy_pass
- if os.environ.has_key('http_proxy') and not self.proxy:
- pattern = re.compile(
- '(?:http://)?' \
- '(?:(?P<user>\w+):(?P<pass>.*)@)?' \
- '(?P<host>[\w\-\.]+)' \
- '(?::(?P<port>\d+))?'
- )
- match = pattern.match(os.environ['http_proxy'])
- if match:
- self.proxy = match.group('host')
- self.proxy_port = match.group('port')
- self.proxy_user = match.group('user')
- self.proxy_pass = match.group('pass')
- else:
- if not self.proxy:
- self.proxy = config.get_value('Boto', 'proxy', None)
- if not self.proxy_port:
- self.proxy_port = config.get_value('Boto', 'proxy_port', None)
- if not self.proxy_user:
- self.proxy_user = config.get_value('Boto', 'proxy_user', None)
- if not self.proxy_pass:
- self.proxy_pass = config.get_value('Boto', 'proxy_pass', None)
-
- if not self.proxy_port and self.proxy:
- print "http_proxy environment variable does not specify " \
- "a port, using default"
- self.proxy_port = self.port
- self.use_proxy = (self.proxy != None)
-
- def get_http_connection(self, host, is_secure):
- conn = self._pool.get_http_connection(host, is_secure)
- if conn is not None:
- return conn
- else:
- return self.new_http_connection(host, is_secure)
-
- def new_http_connection(self, host, is_secure):
- if self.use_proxy:
- host = '%s:%d' % (self.proxy, int(self.proxy_port))
- if host is None:
- host = self.server_name()
- if is_secure:
- boto.log.debug(
- 'establishing HTTPS connection: host=%s, kwargs=%s',
- host, self.http_connection_kwargs)
- if self.use_proxy:
- connection = self.proxy_ssl()
- elif self.https_connection_factory:
- connection = self.https_connection_factory(host)
- elif self.https_validate_certificates and HAVE_HTTPS_CONNECTION:
- connection = https_connection.CertValidatingHTTPSConnection(
- host, ca_certs=self.ca_certificates_file,
- **self.http_connection_kwargs)
- else:
- connection = httplib.HTTPSConnection(host,
- **self.http_connection_kwargs)
- else:
- boto.log.debug('establishing HTTP connection: kwargs=%s' %
- self.http_connection_kwargs)
- connection = httplib.HTTPConnection(host,
- **self.http_connection_kwargs)
- if self.debug > 1:
- connection.set_debuglevel(self.debug)
- # self.connection must be maintained for backwards-compatibility
- # however, it must be dynamically pulled from the connection pool
- # set a private variable which will enable that
- if host.split(':')[0] == self.host and is_secure == self.is_secure:
- self._connection = (host, is_secure)
- return connection
-
- def put_http_connection(self, host, is_secure, connection):
- self._pool.put_http_connection(host, is_secure, connection)
-
- def proxy_ssl(self):
- host = '%s:%d' % (self.host, self.port)
- sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
- try:
- sock.connect((self.proxy, int(self.proxy_port)))
- except:
- raise
- boto.log.debug("Proxy connection: CONNECT %s HTTP/1.0\r\n", host)
- sock.sendall("CONNECT %s HTTP/1.0\r\n" % host)
- sock.sendall("User-Agent: %s\r\n" % UserAgent)
- if self.proxy_user and self.proxy_pass:
- for k, v in self.get_proxy_auth_header().items():
- sock.sendall("%s: %s\r\n" % (k, v))
- sock.sendall("\r\n")
- resp = httplib.HTTPResponse(sock, strict=True, debuglevel=self.debug)
- resp.begin()
-
- if resp.status != 200:
- # Fake a socket error, use a code that make it obvious it hasn't
- # been generated by the socket library
- raise socket.error(-71,
- "Error talking to HTTP proxy %s:%s: %s (%s)" %
- (self.proxy, self.proxy_port, resp.status, resp.reason))
-
- # We can safely close the response, it duped the original socket
- resp.close()
-
- h = httplib.HTTPConnection(host)
-
- if self.https_validate_certificates and HAVE_HTTPS_CONNECTION:
- boto.log.debug("wrapping ssl socket for proxied connection; "
- "CA certificate file=%s",
- self.ca_certificates_file)
- key_file = self.http_connection_kwargs.get('key_file', None)
- cert_file = self.http_connection_kwargs.get('cert_file', None)
- sslSock = ssl.wrap_socket(sock, keyfile=key_file,
- certfile=cert_file,
- cert_reqs=ssl.CERT_REQUIRED,
- ca_certs=self.ca_certificates_file)
- cert = sslSock.getpeercert()
- hostname = self.host.split(':', 0)[0]
- if not https_connection.ValidateCertificateHostname(cert, hostname):
- raise https_connection.InvalidCertificateException(
- hostname, cert, 'hostname mismatch')
- else:
- # Fallback for old Python without ssl.wrap_socket
- if hasattr(httplib, 'ssl'):
- sslSock = httplib.ssl.SSLSocket(sock)
- else:
- sslSock = socket.ssl(sock, None, None)
- sslSock = httplib.FakeSocket(sock, sslSock)
-
- # This is a bit unclean
- h.sock = sslSock
- return h
-
- def prefix_proxy_to_path(self, path, host=None):
- path = self.protocol + '://' + (host or self.server_name()) + path
- return path
-
- def get_proxy_auth_header(self):
- auth = base64.encodestring(self.proxy_user + ':' + self.proxy_pass)
- return {'Proxy-Authorization': 'Basic %s' % auth}
-
def _mexe(self, request, sender=None, override_num_retries=None,
retry_handler=None):
"""
@@ -707,11 +404,12 @@ def _mexe(self, request, sender=None, override_num_retries=None,
Google group by Larry Bates. Thanks!
"""
+ boto.log.debug('')
+ boto.log.debug('>>>>>> Request Details >>>>>>')
boto.log.debug('Method: %s' % request.method)
boto.log.debug('Path: %s' % request.path)
- boto.log.debug('Data: %s' % request.body)
- boto.log.debug('Headers: %s' % request.headers)
boto.log.debug('Host: %s' % request.host)
+
response = None
body = None
e = None
@@ -720,28 +418,62 @@ def _mexe(self, request, sender=None, override_num_retries=None,
else:
num_retries = override_num_retries
i = 0
- connection = self.get_http_connection(request.host, self.is_secure)
+
while i <= num_retries:
- # Use binary exponential backoff to desynchronize client requests
+ # Use binary exponential backoff to de-synchronize client requests
next_sleep = random.random() * (2 ** i)
try:
# we now re-sign each request before it is retried
boto.log.debug('Token: %s' % self.provider.security_token)
request.authorize(connection=self)
- if callable(sender):
- response = sender(connection, request.method, request.path,
- request.body, request.headers)
+
+ url = '%s://%s%s' % (
+ request.protocol,
+ request.host,
+ request.path
+ )
+
+ # This is really, really explicit, but meh.
+ if request.method == 'GET':
+ request_method = requests.get
+ elif request.method == 'POST':
+ request_method = requests.post
+ elif request.method == 'HEAD':
+ request_method = requests.head
+ elif request.method == 'PUT':
+ request_method = requests.put
+ elif request.method == 'DELETE':
+ request_method = requests.delete
else:
- connection.request(request.method, request.path,
- request.body, request.headers)
- response = connection.getresponse()
- location = response.getheader('location')
- # -- gross hack --
- # httplib gets confused with chunked responses to HEAD requests
- # so I have to fake it out
- if request.method == 'HEAD' and getattr(response,
- 'chunked', False):
- response.chunked = 0
+ raise BotoClientError(
+ "Unrecognized HTTP method: %s" % request.method
+ )
+
+ response = request_method(
+ url,
+ data=request.body,
+ headers=request.headers,
+ verify=self.https_validate_certificates,
+ timeout=self.timeout,
+ #config={'verbose': sys.stderr},
+ )
+ boto.log.debug('Headers: %s' % response.request.headers)
+ boto.log.debug('Params: %s' % response.request.params)
+ boto.log.debug('Data: %s' % request.body)
+
+ status_reason = HTTP_REASON_CODES.get(response.status_code, 'Unknown')
+ setattr(response, 'reason', status_reason)
+
+ boto.log.debug('')
+ boto.log.debug('<<<<<< Response Details <<<<<<')
+ boto.log.debug('Status: %s' % response.status_code)
+ boto.log.debug('Headers: %s' % response.headers)
+ boto.log.debug('Content: %s' % response.content)
+ boto.log.debug('<' * 30)
+ boto.log.debug('')
+
+ location = response.headers['location']
+
if callable(retry_handler):
status = retry_handler(response, i, next_sleep)
if status:
@@ -750,26 +482,27 @@ def _mexe(self, request, sender=None, override_num_retries=None,
boto.log.debug(msg)
time.sleep(next_sleep)
continue
- if response.status == 500 or response.status == 503:
- msg = 'Received %d response. ' % response.status
+ if response.status_code == 500 or response.status_code == 503:
+ msg = 'Received %d response. ' % response.status_code
msg += 'Retrying in %3.1f seconds' % next_sleep
boto.log.debug(msg)
- body = response.read()
- elif response.status < 300 or response.status >= 400 or \
- not location:
- self.put_http_connection(request.host, self.is_secure,
- connection)
+ body = response.text
+ elif response.status_code < 300 or \
+ response.status_code >= 400 or \
+ not location:
+ # Success.
return response
else:
+ # Not sure what happened, appears to be a redir. Grab
+ # the components out of the 'location' header value.
scheme, request.host, request.path, \
params, query, fragment = urlparse.urlparse(location)
if query:
request.path += '?' + query
msg = 'Redirecting: %s' % scheme + '://'
msg += request.host + request.path
boto.log.debug(msg)
- connection = self.get_http_connection(request.host,
- scheme == 'https')
+ # Fall through to another re-try with the modified values.
continue
except self.http_exceptions, e:
for unretryable in self.http_unretryable_exceptions:
@@ -780,16 +513,14 @@ def _mexe(self, request, sender=None, override_num_retries=None,
raise e
boto.log.debug('encountered %s exception, reconnecting' % \
e.__class__.__name__)
- connection = self.new_http_connection(request.host,
- self.is_secure)
time.sleep(next_sleep)
i += 1
# If we made it here, it's because we have exhausted our retries
# and stil haven't succeeded. So, if we have a response object,
# use it to raise an exception.
# Otherwise, raise the exception that must have already h#appened.
if response:
- raise BotoServerError(response.status, response.reason, body)
+ raise BotoServerError(response.status_code, status.reason, body)
elif e:
raise e
else:
@@ -801,23 +532,16 @@ def build_base_http_request(self, method, path, auth_path,
path = self.get_path(path)
if auth_path is not None:
auth_path = self.get_path(auth_path)
- if params == None:
+ if params is None:
params = {}
else:
params = params.copy()
- if headers == None:
+ if headers is None:
headers = {}
else:
headers = headers.copy()
host = host or self.host
- if self.use_proxy:
- if not auth_path:
- auth_path = path
- path = self.prefix_proxy_to_path(path, host)
- if self.proxy_user and self.proxy_pass and not self.is_secure:
- # If is_secure, we don't have to set the proxy authentication
- # header here, we did that in the CONNECT to the proxy.
- headers.update(self.get_proxy_auth_header())
+
return HTTPRequest(method, self.protocol, host, self.port,
path, auth_path, params, headers, data)
@@ -880,56 +604,56 @@ def get_list(self, action, params, markers, path='/',
if not parent:
parent = self
response = self.make_request(action, params, path, verb)
- body = response.read()
+ body = response.content
boto.log.debug(body)
if not body:
boto.log.error('Null body %s' % body)
- raise self.ResponseError(response.status, response.reason, body)
- elif response.status == 200:
+ raise self.ResponseError(response.status_code, response.reason, body)
+ elif response.status_code == 200:
rs = ResultSet(markers)
h = boto.handler.XmlHandler(rs, parent)
xml.sax.parseString(body, h)
return rs
else:
- boto.log.error('%s %s' % (response.status, response.reason))
+ boto.log.error('%s %s' % (response.status_code, response.reason))
boto.log.error('%s' % body)
- raise self.ResponseError(response.status, response.reason, body)
+ raise self.ResponseError(response.status_code, response.reason, body)
def get_object(self, action, params, cls, path='/',
parent=None, verb='GET'):
if not parent:
parent = self
response = self.make_request(action, params, path, verb)
- body = response.read()
+ body = response.content
boto.log.debug(body)
if not body:
boto.log.error('Null body %s' % body)
- raise self.ResponseError(response.status, response.reason, body)
- elif response.status == 200:
+ raise self.ResponseError(response.status_code, response.reason, body)
+ elif response.status_code == 200:
obj = cls(parent)
h = boto.handler.XmlHandler(obj, parent)
xml.sax.parseString(body, h)
return obj
else:
- boto.log.error('%s %s' % (response.status, response.reason))
+ boto.log.error('%s %s' % (response.status_code, response.reason))
boto.log.error('%s' % body)
- raise self.ResponseError(response.status, response.reason, body)
+ raise self.ResponseError(response.status_code, response.reason, body)
def get_status(self, action, params, path='/', parent=None, verb='GET'):
if not parent:
parent = self
response = self.make_request(action, params, path, verb)
- body = response.read()
+ body = response.content
boto.log.debug(body)
if not body:
boto.log.error('Null body %s' % body)
- raise self.ResponseError(response.status, response.reason, body)
- elif response.status == 200:
+ raise self.ResponseError(response.status_code, response.reason, body)
+ elif response.status_code == 200:
rs = ResultSet()
h = boto.handler.XmlHandler(rs, parent)
xml.sax.parseString(body, h)
return rs.status
else:
- boto.log.error('%s %s' % (response.status, response.reason))
+ boto.log.error('%s %s' % (response.status_code, response.reason))
boto.log.error('%s' % body)
- raise self.ResponseError(response.status, response.reason, body)
+ raise self.ResponseError(response.status_code, response.reason, body)
View
17 boto/dynamodb/layer1.py
@@ -110,23 +110,24 @@ def make_request(self, action, body='', object_hook=None):
"""
:raises: ``DynamoDBExpiredTokenError`` if the security token expires.
"""
- headers = {'X-Amz-Target' : '%s_%s.%s' % (self.ServiceName,
- self.Version, action),
- 'Content-Type' : 'application/x-amz-json-1.0',
- 'Content-Length' : str(len(body))}
+ headers = {
+ 'X-Amz-Target' : '%s_%s.%s' % (self.ServiceName, self.Version, action),
+ 'Content-Type' : 'application/x-amz-json-1.0',
+ 'Content-Length' : str(len(body)),
+ }
http_request = self.build_base_http_request('POST', '/', '/',
{}, headers, body, None)
response = self._mexe(http_request, sender=None,
override_num_retries=10,
retry_handler=self._retry_handler)
- response_body = response.read()
+ response_body = response.content
boto.log.debug(response_body)
return json.loads(response_body, object_hook=object_hook)
def _retry_handler(self, response, i, next_sleep):
status = None
- if response.status == 400:
- response_body = response.read()
+ if response.status_code == 400:
+ response_body = response.content
boto.log.debug(response_body)
json_response = json.loads(response_body)
if self.ThruputError in json_response.get('__type'):
@@ -144,7 +145,7 @@ def _retry_handler(self, response, i, next_sleep):
self._update_provider()
status = (msg, i+self.num_retries-1, next_sleep)
else:
- raise self.ResponseError(response.status, response.reason,
+ raise self.ResponseError(response.status_code, response.reason,
json_response)
return status
View
8 boto/ecs/__init__.py
@@ -58,13 +58,13 @@ def get_response(self, action, params, page=0, itemSet=None):
if page:
params['ItemPage'] = page
response = self.make_request(None, params, "/onca/xml")
- body = response.read()
+ body = response.content
boto.log.debug(body)
- if response.status != 200:
- boto.log.error('%s %s' % (response.status, response.reason))
+ if response.status_code != 200:
+ boto.log.error('%s %s' % (response.status_code, response.reason))
boto.log.error('%s' % body)
- raise self.ResponseError(response.status, response.reason, body)
+ raise self.ResponseError(response.status_code, response.reason, body)
if itemSet == None:
rs = ItemSet(self, action, params, page)
View
70 boto/fps/connection.py
@@ -83,21 +83,21 @@ def install_caller_instruction(self, token_type="Unrestricted",
response = self.install_payment_instruction("MyRole=='Caller';",
token_type=token_type,
transaction_id=transaction_id)
- body = response.read()
- if(response.status == 200):
+ body = response.content
+ if response.status_code == 200:
rs = ResultSet()
h = handler.XmlHandler(rs, self)
xml.sax.parseString(body, h)
caller_token = rs.TokenId
try:
boto.config.save_system_option("FPS", "caller_token",
caller_token)
- except(IOError):
+ except IOError:
boto.config.save_user_option("FPS", "caller_token",
caller_token)
return caller_token
else:
- raise FPSResponseError(response.status, response.reason, body)
+ raise FPSResponseError(response.status_code, response.reason, body)
def install_recipient_instruction(self, token_type="Unrestricted",
transaction_id=None):
@@ -109,22 +109,22 @@ def install_recipient_instruction(self, token_type="Unrestricted",
response = self.install_payment_instruction("MyRole=='Recipient';",
token_type=token_type,
transaction_id=transaction_id)
- body = response.read()
- if(response.status == 200):
+ body = response.content
+ if response.status_code == 200:
rs = ResultSet()
h = handler.XmlHandler(rs, self)
xml.sax.parseString(body, h)
recipient_token = rs.TokenId
try:
boto.config.save_system_option("FPS", "recipient_token",
recipient_token)
- except(IOError):
+ except IOError:
boto.config.save_user_option("FPS", "recipient_token",
recipient_token)
return recipient_token
else:
- raise FPSResponseError(response.status, response.reason, body)
+ raise FPSResponseError(response.status_code, response.reason, body)
def make_marketplace_registration_url(self, returnURL, pipelineName,
maxFixedFee=0.0, maxVariableFee=0.0,
@@ -266,14 +266,14 @@ def pay(self, transactionAmount, senderTokenId,
response = self.make_request("Reserve", params)
else:
response = self.make_request("Pay", params)
- body = response.read()
- if(response.status == 200):
+ body = response.content
+ if(response.status_code == 200):
rs = ResultSet()
h = handler.XmlHandler(rs, self)
xml.sax.parseString(body, h)
return rs
else:
- raise FPSResponseError(response.status, response.reason, body)
+ raise FPSResponseError(response.status_code, response.reason, body)
def get_transaction_status(self, transactionId):
"""
@@ -283,14 +283,14 @@ def get_transaction_status(self, transactionId):
params['TransactionId'] = transactionId
response = self.make_request("GetTransactionStatus", params)
- body = response.read()
- if(response.status == 200):
+ body = response.content
+ if(response.status_code == 200):
rs = ResultSet()
h = handler.XmlHandler(rs, self)
xml.sax.parseString(body, h)
return rs
else:
- raise FPSResponseError(response.status, response.reason, body)
+ raise FPSResponseError(response.status_code, response.reason, body)
def cancel(self, transactionId, description=None):
"""
@@ -302,14 +302,14 @@ def cancel(self, transactionId, description=None):
params['description'] = description
response = self.make_request("Cancel", params)
- body = response.read()
- if(response.status == 200):
+ body = response.content
+ if(response.status_code == 200):
rs = ResultSet()
h = handler.XmlHandler(rs, self)
xml.sax.parseString(body, h)
return rs
else:
- raise FPSResponseError(response.status, response.reason, body)
+ raise FPSResponseError(response.status_code, response.reason, body)
def settle(self, reserveTransactionId, transactionAmount=None):
"""
@@ -321,14 +321,14 @@ def settle(self, reserveTransactionId, transactionAmount=None):
params['TransactionAmount'] = transactionAmount
response = self.make_request("Settle", params)
- body = response.read()
- if(response.status == 200):
+ body = response.content
+ if(response.status_code == 200):
rs = ResultSet()
h = handler.XmlHandler(rs, self)
xml.sax.parseString(body, h)
return rs
else:
- raise FPSResponseError(response.status, response.reason, body)
+ raise FPSResponseError(response.status_code, response.reason, body)
def refund(self, callerReference, transactionId, refundAmount=None,
callerDescription=None):
@@ -345,14 +345,14 @@ def refund(self, callerReference, transactionId, refundAmount=None,
params['CallerDescription'] = callerDescription
response = self.make_request("Refund", params)
- body = response.read()
- if(response.status == 200):
+ body = response.content
+ if(response.status_code == 200):
rs = ResultSet()
h = handler.XmlHandler(rs, self)
xml.sax.parseString(body, h)
return rs
else:
- raise FPSResponseError(response.status, response.reason, body)
+ raise FPSResponseError(response.status_code, response.reason, body)
def get_recipient_verification_status(self, recipientTokenId):
"""
@@ -362,14 +362,14 @@ def get_recipient_verification_status(self, recipientTokenId):
params['RecipientTokenId'] = recipientTokenId
response = self.make_request("GetRecipientVerificationStatus", params)
- body = response.read()
- if(response.status == 200):
+ body = response.content
+ if(response.status_code == 200):
rs = ResultSet()
h = handler.XmlHandler(rs, self)
xml.sax.parseString(body, h)
return rs
else:
- raise FPSResponseError(response.status, response.reason, body)
+ raise FPSResponseError(response.status_code, response.reason, body)
def get_token_by_caller_reference(self, callerReference):
"""
@@ -379,14 +379,14 @@ def get_token_by_caller_reference(self, callerReference):
params['CallerReference'] = callerReference
response = self.make_request("GetTokenByCaller", params)
- body = response.read()
- if(response.status == 200):
+ body = response.content
+ if(response.status_code == 200):
rs = ResultSet()
h = handler.XmlHandler(rs, self)
xml.sax.parseString(body, h)
return rs
else:
- raise FPSResponseError(response.status, response.reason, body)
+ raise FPSResponseError(response.status_code, response.reason, body)
def get_token_by_caller_token(self, tokenId):
"""
@@ -396,24 +396,24 @@ def get_token_by_caller_token(self, tokenId):
params['TokenId'] = tokenId
response = self.make_request("GetTokenByCaller", params)
- body = response.read()
- if(response.status == 200):
+ body = response.content
+ if(response.status_code == 200):
rs = ResultSet()
h = handler.XmlHandler(rs, self)
xml.sax.parseString(body, h)
return rs
else:
- raise FPSResponseError(response.status, response.reason, body)
+ raise FPSResponseError(response.status_code, response.reason, body)
def verify_signature(self, end_point_url, http_parameters):
params = dict(
UrlEndPoint = end_point_url,
HttpParameters = http_parameters,
)
response = self.make_request("VerifySignature", params)
- body = response.read()
- if(response.status != 200):
- raise FPSResponseError(response.status, response.reason, body)
+ body = response.content
+ if(response.status_code != 200):
+ raise FPSResponseError(response.status_code, response.reason, body)
rs = ResultSet()
h = handler.XmlHandler(rs, self)
xml.sax.parseString(body, h)
View
12 boto/gs/bucket.py
@@ -64,15 +64,15 @@ def get_acl_helper(self, key_name, headers, query_args):
response = self.connection.make_request('GET', self.name, key_name,
query_args=query_args,
headers=headers)
- body = response.read()
- if response.status == 200:
+ body = response.content
+ if response.status_code == 200:
acl = ACL(self)
h = handler.XmlHandler(acl, self)
xml.sax.parseString(body, h)
return acl
else:
raise self.connection.provider.storage_response_error(
- response.status, response.reason, body)
+ response.status_code, response.reason, body)
def get_acl(self, key_name='', headers=None, version_id=None):
"""returns a bucket's acl. We include a version_id argument
@@ -97,10 +97,10 @@ def set_canned_acl_helper(self, acl_str, key_name, headers, query_args):
response = self.connection.make_request('PUT', self.name, key_name,
headers=headers, query_args=query_args)
- body = response.read()
- if response.status != 200:
+ body = response.content
+ if response.status_code != 200:
raise self.connection.provider.storage_response_error(
- response.status, response.reason, body)
+ response.status_code, response.reason, body)
def set_canned_acl(self, acl_str, key_name='', headers=None,
version_id=None):
View
10 boto/gs/connection.py
@@ -82,13 +82,13 @@ def create_bucket(self, bucket_name, headers=None,
'</CreateBucketConfiguration>' % location)
response = self.make_request('PUT', bucket_name, headers=headers,
data=data)
- body = response.read()
- if response.status == 409:
+ body = response.content
+ if response.status_code == 409:
raise self.provider.storage_create_error(
- response.status, response.reason, body)
- if response.status == 200:
+ response.status_code, response.reason, body)
+ if response.status_code == 200:
return self.bucket_class(self, bucket_name)
else:
raise self.provider.storage_response_error(
- response.status, response.reason, body)
+ response.status_code, response.reason, body)
View
2 boto/gs/resumable_upload_handler.py
@@ -234,7 +234,7 @@ def _query_server_pos(self, conn, file_length):
if not got_valid_response:
raise ResumableUploadException(
'Couldn\'t parse upload server state query response (%s)' %
- str(resp.getheaders()), ResumableTransferDisposition.START_OVER)
+ str(resp.headers), ResumableTransferDisposition.START_OVER)
if conn.debug >= 1:
print 'Server has: Range: %d - %d.' % (server_start, server_end)
return (server_start, server_end)
View
8 boto/iam/connection.py
@@ -54,18 +54,18 @@ def get_response(self, action, params, path='/', parent=None,
if not parent:
parent = self
response = self.make_request(action, params, path, verb)
- body = response.read()
+ body = response.content
boto.log.debug(body)
- if response.status == 200:
+ if response.status_code == 200:
e = boto.jsonresponse.Element(list_marker=list_marker,
pythonize_name=True)
h = boto.jsonresponse.XmlHandler(e, parent)
h.parse(body)
return e
else:
- boto.log.error('%s %s' % (response.status, response.reason))
+ boto.log.error('%s %s' % (response.status_code, response.reason))
boto.log.error('%s' % body)
- raise self.ResponseError(response.status, response.reason, body)
+ raise self.ResponseError(response.status_code, response.reason, body)
#
# Group methods
View
4 boto/mturk/connection.py
@@ -735,15 +735,15 @@ def _process_response(self, response, marker_elems=None):
"""
Helper to process the xml response from AWS
"""
- body = response.read()
+ body = response.content
#print body
if '<Errors>' not in body:
rs = ResultSet(marker_elems)
h = handler.XmlHandler(rs, self)
xml.sax.parseString(body, h)
return rs
else:
- raise MTurkRequestError(response.status, response.reason, body)
+ raise MTurkRequestError(response.status_code, response.reason, body)
@staticmethod
def get_keywords_as_string(keywords):
View
10 boto/roboto/awsqueryrequest.py
@@ -201,7 +201,7 @@ def get_connection(self, **args):
def status(self):
retval = None
if self.http_response is not None:
- retval = self.http_response.status
+ retval = self.http_response.status_code
return retval
@property
@@ -298,19 +298,19 @@ def send(self, verb='GET', **args):
self.http_response = conn.make_request(self.name(),
self.request_params,
verb=verb)
- self.body = self.http_response.read()
+ self.body = self.http_response.response
boto.log.debug(self.body)
- if self.http_response.status == 200:
+ if self.http_response.status_code == 200:
self.aws_response = boto.jsonresponse.Element(list_marker=self.list_markers,
item_marker=self.item_markers)
h = boto.jsonresponse.XmlHandler(self.aws_response, self)
h.parse(self.body)
return self.aws_response
else:
- boto.log.error('%s %s' % (self.http_response.status,
+ boto.log.error('%s %s' % (self.http_response.status_code,
self.http_response.reason))
boto.log.error('%s' % self.body)
- raise conn.ResponseError(self.http_response.status,
+ raise conn.ResponseError(self.http_response.status_code,
self.http_response.reason,
self.body)
View
42 boto/route53/connection.py
@@ -89,10 +89,10 @@ def get_all_hosted_zones(self, start_marker=None, zone_list=None):
params = {'marker': start_marker}
response = self.make_request('GET', '/%s/hostedzone' % self.Version,