python - 类型错误:需要一个可读的缓冲区对象

标签 python typeerror

当我尝试使用 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

我正在使用此代码访问 API

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

你能帮我解决这个问题吗?

最佳答案

查看错误信息

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

这表明您在应该传递“正文”的地方传递了“标题”。

所以,尝试调用

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

关于python - 类型错误:需要一个可读的缓冲区对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13318591/

相关文章:

javascript - 又一个 'Uncaught TypeError: Cannot call method ' apply ' of undefined '

python - 使用系列更新 DataFrame 中的列

javascript - 未捕获的语法错误 : ) missing after argument list in asp.net mvc 应用程序 javascript

python-3.x - plt.imshow() 中图像数据的尺寸无效

python - PinoroEnviro+ 类型错误 : argument should be integer or bytes-like object, 而不是 'str'

javascript - 未捕获的类型错误 javascript 方法

python - 使用 C 扩展扩展 python

python - 未命名整数文字的意外引用计数

python - 在 heroku/module 上部署 django 应用程序时出现问题,找不到错误

python - 将 Sum 添加到 pandas 数据框中的所有分组行