ファイル(オーディオファイル)をdjango webappからdjango restサービスにアップロードしようとしています。Djangoファイルのアップロード - filenoエラー
形式:
<form method="post" action="/" name="submit" enctype="multipart/form-data">
{% csrf_token %}
<input type="file" name="uploaded_file"><br /><br />
<input type="submit" name="submit" value="Submit">
</form>
ビュー:
from poster.streaminghttp import register_openers
from poster.encode import multipart_encode
import urllib2
<...>
def post(self, request):
"""
POST request: handles file upload to web service
"""
uploaded_file = request.FILES['uploaded_file']
server = "http://127.0.0.1:8000"
headers = {}
# Register the streaming http handlers with urllib2
register_openers()
data = {
'uploaded_file' : uploaded_file,
'file_name' : uploaded_file.name,
'additionalattr': 111,
}
datagen, headers = multipart_encode(data)
headers['Authorization'] = 'Token <...>'
headers['Connection']='keep-alive'
urllib_request = urllib2.Request('%s/file_upload/' % (server), datagen, headers)
json_response = json.loads(urllib2.urlopen(urllib_request).read())
return <...>
私はファイルをアップロードすると、私はmultipart_encodeによって引き起こされる、次のエラーコードを取得:
Traceback (most recent call last):
File "/Users/phoebus/Library/Python/2.7/lib/python/site-packages/django/core/handlers/exception.py", line 39, in inner
response = get_response(request)
File "/Users/phoebus/Library/Python/2.7/lib/python/site-packages/django/core/handlers/base.py", line 186, in _get_response
response = self.process_exception_by_middleware(e, request)
File "/Users/phoebus/Library/Python/2.7/lib/python/site-packages/django/core/handlers/base.py", line 184, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/Users/phoebus/Library/Python/2.7/lib/python/site-packages/django/contrib/auth/decorators.py", line 23, in _wrapped_view
return view_func(request, *args, **kwargs)
File "/Users/phoebus/Library/Python/2.7/lib/python/site-packages/django/views/generic/base.py", line 68, in view
return self.dispatch(request, *args, **kwargs)
File "/Users/phoebus/Library/Python/2.7/lib/python/site-packages/django/views/generic/base.py", line 88, in dispatch
return handler(request, *args, **kwargs)
File "/Users/phoebus/Projects/speechanalyzerwebapp/speechanalyzerwebapp/welcome.py", line 41, in post
datagen, headers = multipart_encode(data)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/poster/encode.py", line 411, in multipart_encode
headers = get_headers(params, boundary)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/poster/encode.py", line 311, in get_headers
headers['Content-Length'] = str(get_body_size(params, boundary))
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/poster/encode.py", line 302, in get_body_size
size = sum(p.get_size(boundary) for p in MultipartParam.from_params(params))
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/poster/encode.py", line 177, in from_params
filetype=filetype, fileobj=value))
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/poster/encode.py", line 108, in __init__
self.filesize = os.fstat(fileobj.fileno()).st_size
UnsupportedOperation: fileno
を誰が私を助けることができます何がうまくいかないのか、それをどうやって修正できるのか理解していますか?
ありがとうございます!
を更新し、古い更新チェック最新バージョンhereのですか? –
いいえ、どちらもターミナル – phoebus
から実行されているのは、メンテナンスされていない 'poster'ライブラリを使用しているようですが、その最後のアップデートは2009です。 –