我正在尝试向imagekit.io API发出POST请求以上传图像。 该文档非常缺乏,但是当尝试遵循基本的请求结构时,出现以下错误:
>>> r = requests.post(url, params=payload)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python27\lib\site-packages\requests\api.py", line 112, in post
return request('post', url, data=data, json=json, **kwargs)
File "C:\Python27\lib\site-packages\requests\api.py", line 58, in request
return session.request(method=method, url=url, **kwargs)
File "C:\Python27\lib\site-packages\requests\sessions.py", line 508, in request
resp = self.send(prep, **send_kwargs)
File "C:\Python27\lib\site-packages\requests\sessions.py", line 658, in send
r.content
File "C:\Python27\lib\site-packages\requests\models.py", line 823, in content
self._content = bytes().join(self.iter_content(CONTENT_CHUNK_SIZE)) or bytes()
File "C:\Python27\lib\site-packages\requests\models.py", line 748, in generate
raise ChunkedEncodingError(e)
requests.exceptions.ChunkedEncodingError: ("Connection broken: error(10053, 'An established connection was aborted by the software in your host machine')", error(10053, 'An established connection was aborted by the software in your host machine'))
以下是有关有效负载的信息:
payload = {'apiKey': api_key, 'filename': file_name,
'timestamp': timestamp, 'signature': signed_key,
'file': encoded_file}
encoded_file使用以下功能获取:
def get_file(file_name):
with open(file_name, "rb") as image_file:
encoded_file = base64.b64encode(image_file.read())
return encoded_file
自从我发现一些人说这可能是Python2.7的问题以来,我就试图改编脚本并从Python3运行它。