简体   繁体   中英

TypeError: expected a readable buffer object

I am running into the following error when I try to connect to an API using M2Crypto HTTPSConnection library using the GET method.

Traceback (most recent call last):
  File "osg-gridadmin-cert-request", line 665, in <module>
    status = check_quota_limit(request_count)
  File "osg-gridadmin-cert-request", line 543, in check_quota_limit
    conn.request('GET', arguments['quotaurl'], headers)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py", line 941, in request
    self._send_request(method, url, body, headers)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py", line 975, in _send_request
    self.endheaders(body)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py", line 937, in endheaders
    self._send_output(message_body)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py", line 801, in _send_output
    self.send(message_body)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py", line 773, in send
    self.sock.sendall(data)
  File "build/bdist.macosx-10.7-intel/egg/M2Crypto/SSL/Connection.py", line 217, in write
    return self._write_nbio(data)
  File "build/bdist.macosx-10.7-intel/egg/M2Crypto/SSL/Connection.py", line 202, in _write_nbio
    return m2.ssl_write_nbio(self.ssl, data)
TypeError: expected a readable buffer object

I am accessing the API using this code

conn = M2Crypto.httpslib.HTTPSConnection(arguments['host'],
            ssl_context=ssl_context)
        conn.request('GET', arguments['quotaurl'], headers)
        response = conn.getresponse()

Could you please help me with this problem?

See the error message

self._send_request(method, url, body, headers)

This indicates that you are passing "headers" where you are supposed to pass "body".

So, try calling

conn.request('GET', arguments['quotaurl'], None, headers)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM