当我尝试使用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()
你能帮我解决这个问题吗?
答案 0 :(得分:1)
请参阅错误消息
self._send_request(method, url, body, headers)
这表示您正在传递“标题”,您应该传递“正文”。
所以,试着打电话
conn.request('GET', arguments['quotaurl'], None, headers)