我对 Python/Django 和 Minio 服务器的 POST 请求有问题,这是代码
from django.http import HttpResponse
import json
from minio import Minio
minioClient = Minio('mypath:9000',
access_key='mykey',
secret_key='mysecret',
secure=False)
def getMessage(request):
if request.method == 'POST':
data = json.loads(request.body.decode('utf-8'))
for obj in data['files']:
...do some stuff....
minioClient.fget_object(myvar, myvar2, '/tmp/processing')
return HttpResponse(file)
问题是如果我一开始不删除导入,请求将无法工作,我不明白为什么。这是生成的错误:
HTTPConnectionPool(host='myhost', port=8001):
Max retries exceeded with url: /myurl/
(Caused NewConnectionError
('<requests.packages.urllib3.connection.HTTPConnection object at 0x7fcbeab21160>:
Failed to establish a new connection: [Errno 111] Connection refused',))
这是发出请求的脚本:
.... some code....
try:
r = requests.post("http://myurl:8001/mypath/", data=my_data, timeout=1)
except Exception as e:
print(e)
我已经尝试增加超时,但它不起作用,当然,我已经在另一个脚本中测试了 Minio 部分,导入它仅在这个请求脚本中生成此错误。
感谢帮助
请您参考如下方法:
来自 urllib3 的文档:
request(method, url, fields=None, headers=None, **urlopen_kw)¶ Make a request using urlopen() with the appropriate encoding of fields based on the method used.
也许你可以尝试这样的事情:
r = http.request('POST', "http://myurl:8001/mypath/",
headers={'Content-Type': 'application/json'},
body=encoded_data)
