Ask Your Question

unable to upload image using python-glanceclient

asked 2017-10-03 17:44:35 -0500

linuxuser26 gravatar image

updated 2017-10-03 17:46:26 -0500

I'm using Python API v2 and I'm unable to upload images to Glance.Here's the code snippet I'm using to upload images to Glance.

I'd appreciate any pointers.

from keystoneauth1 import loading
from keystoneauth1 import session
from glanceclient import Client

loader = loading.get_plugin_loader('password')
auth = loader.load_from_options(
glance_session = session.Session(auth=auth)
glance = Client('2', session=glance_session)

for image in glance.images.list():  # This works
    print image

image = glance.images.create(name="my_image")
glance.images.upload(, open('/tmp/image.qcow2', 'rb'))

It got stuck here:

-> image = glance.images.create(name="my_image")
(Pdb) p
(Pdb) n
> /virtualenv/cfme_tests/scripts/<module>()
-> glance.images.upload(, open('/tmp/image.qcow2', 'rb'))
(Pdb) n
> /virtualenv/lib/python2.7/site-packages/glanceclient/v2/
-> resp, body = self.http_client.put(url, headers=hdrs, data=body)
(Pdb) p url

When I interrupted from the keyboard, this was the backtrace:

 Pdb) n
Traceback (most recent call last):
  File "./scripts/", line 39, in <module>
    glance.images.upload(, open('/tmp/image.qcow2', 'rb'))
  File "/virtualenv/lib/python2.7/site-packages/glanceclient/common/", line 545, in inner
    return RequestIdProxy(wrapped(*args, **kwargs))
  File "/virtualenv/lib/python2.7/site-packages/glanceclient/v2/", line 231, in upload
    resp, body = self.http_client.put(url, headers=hdrs, data=body)
  File "/virtualenv/lib/python2.7/site-packages/keystoneauth1/", line 232, in put
    return self.request(url, 'PUT', **kwargs)
  File "/virtualenv/lib/python2.7/site-packages/glanceclient/common/", line 338, in request
  File "/virtualenv/lib/python2.7/site-packages/keystoneauth1/", line 148, in request
    return self.session.request(url, method, **kwargs)
  File "/virtualenv/lib/python2.7/site-packages/positional/", line 101, in inner
    return wrapped(*args, **kwargs)
  File "/virtualenv/lib/python2.7/site-packages/keystoneauth1/", line 616, in request
    resp = send(**kwargs)
  File "/virtualenv/lib/python2.7/site-packages/keystoneauth1/", line 674, in _send_request
    resp = self.session.request(method, url, **kwargs)
  File "/virtualenv/lib/python2.7/site-packages/requests/", line 513, in request
    resp = self.send(prep, **send_kwargs)
  File "/virtualenv/lib/python2.7/site-packages/requests/", line 623, in send
    r = adapter.send(request, **kwargs)
  File "/virtualenv/lib/python2.7/site-packages/requests/", line 463, in send
  File "/usr/lib64/python2.7/", line 826, in send
  File "/usr/lib64/python2.7/", line 224, in meth
    return getattr(self._sock,name)(*args)
edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2017-10-04 19:45:42 -0500

ericwong gravatar image


I also hit the same and got 502 error (seen below). looks like this the example in ( need update and adding extra fields works for me...

image = glance.images.create(name=IMAGE_NAME,container_format='bare',disk_format='qcow2')

Traceback (most recent call last): File "", line 40, in <module> glance.images.upload(, open(IMAGE_FILE, 'rb')) File "/usr/local/lib/python2.7/dist-packages/glanceclient/common/", line 545, in inner return RequestIdProxy(wrapped(args, *kwargs)) File "/usr/local/lib/python2.7/dist-packages/glanceclient/v2/", line 232, in upload resp, body = self.http_client.put(url, headers=hdrs, data=body) File "/usr/local/lib/python2.7/dist-packages/keystoneauth1/", line 313, in put return self.request(url, 'PUT', **kwargs) File "/usr/local/lib/python2.7/dist-packages/glanceclient/common/", line 349, in request return self._handle_response(resp) File "/usr/local/lib/python2.7/dist-packages/glanceclient/common/", line 98, in _handle_response raise exc.from_response(resp, resp.content) glanceclient.exc.HTTPBadGateway: 502 Bad Gateway: Bad Gateway: The proxy server received an invalid: response from an upstream server.: Apache/2.4.18 (Ubuntu) Server at Port 80 (HTTP 502)

edit flag offensive delete link more

Get to know Ask OpenStack

Resources for moderators

Question Tools


Asked: 2017-10-03 17:44:35 -0500

Seen: 467 times

Last updated: Oct 03 '17