我想在python脚本中编写以下针对未指定格式的大型文件的curl POST请求:
curl http://myurl -F file=@local/path/to/file -X POST -H "Archive: archive-name" -H "Key: key" -H "Path: /landing/path/to/file"
我已经尝试过使用该语法,但是它不起作用
import requests
headers = {
'X-Archive': 'archive-name',
'X-Key': 'key',
'X-Path': '/landing/path/to/file',
}
files = {
'file': ('local/path/to/file', open('local/path/to/file', 'rb')),
}
response = requests.post('http://myurl/', headers=headers, files=files)
我遇到以下错误
Traceback (most recent call last):
File "python_curl.py", line 25, in <module>
response = requests.post('http://myurl', headers=headers, files=files)
File "/usr/lib/python2.7/site-packages/requests/api.py", line 108, in post
return request('post', url, data=data, json=json, **kwargs)
File "/usr/lib/python2.7/site-packages/requests/api.py", line 50, in request
response = session.request(method=method, url=url, **kwargs)
File "/usr/lib/python2.7/site-packages/requests/sessions.py", line 450, in request
prep = self.prepare_request(req)
File "/usr/lib/python2.7/site-packages/requests/sessions.py", line 381, in prepare_request
hooks=merge_hooks(request.hooks, self.hooks),
File "/usr/lib/python2.7/site-packages/requests/models.py", line 307, in prepare
self.prepare_body(data, files, json)
File "/usr/lib/python2.7/site-packages/requests/models.py", line 452, in prepare_body
(body, content_type) = self._encode_files(files, data)
File "/usr/lib/python2.7/site-packages/requests/models.py", line 150, in _encode_files
fdata = fp.read()
MemoryError
怎么可能呢?