简体   繁体   English

TypeError:期望一个可读的缓冲区对象

[英]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. 当我尝试使用GET方法使用M2Crypto HTTPSConnection库连接到API时,我遇到以下错误。

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 我正在使用此代码访问API

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)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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