2
我正在使用django並將構建發送到travis-ci,這對我的測試構建失敗。這是有問題的行是在這個函數...python subprocess Popen在本地和遠程系統上的行爲不同
from subprocess import Popen, PIPE
def make_mp3(path, blob):
process = Popen(
['lame', '-', '--comp', '40', path], stdin=PIPE, stdout=PIPE, stderr=PIPE)
stdout_data = process.communicate(input=blob.read())
return stdout_data
調用該函數的行是在這裏:
make_mp3(mp3_path, request.FILES['audio_file'])
我的本地系統上測試運行良好,並通過。我一直在使用這個函數一段時間,它的行爲和預期的一樣。但是,當我把它發送給特拉維斯-CI爲構建它給了我這個回溯...
======================================================================
ERROR: test_post_upload_audio_word (define.tests.ViewTests)
Testing the audio upload function for word audio
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/travis/build/deltaskelta/langalang/define/tests.py", line 827, in test_post_upload_audio_word
'audio_file': audio_file})
File "/home/travis/virtualenv/python2.7.12/lib/python2.7/site-packages/django/test/client.py", line 541, in post
secure=secure, **extra)
File "/home/travis/virtualenv/python2.7.12/lib/python2.7/site-packages/django/test/client.py", line 343, in post
secure=secure, **extra)
File "/home/travis/virtualenv/python2.7.12/lib/python2.7/site-packages/django/test/client.py", line 409, in generic
return self.request(**r)
File "/home/travis/virtualenv/python2.7.12/lib/python2.7/site-packages/django/test/client.py", line 494, in request
six.reraise(*exc_info)
File "/home/travis/virtualenv/python2.7.12/lib/python2.7/site-packages/django/core/handlers/exception.py", line 39, in inner
response = get_response(request)
File "/home/travis/virtualenv/python2.7.12/lib/python2.7/site-packages/django/core/handlers/base.py", line 187, in _get_response
response = self.process_exception_by_middleware(e, request)
File "/home/travis/virtualenv/python2.7.12/lib/python2.7/site-packages/django/core/handlers/base.py", line 185, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/home/travis/virtualenv/python2.7.12/lib/python2.7/site-packages/django/views/generic/base.py", line 68, in view
return self.dispatch(request, *args, **kwargs)
File "/home/travis/virtualenv/python2.7.12/lib/python2.7/site-packages/django/utils/decorators.py", line 67, in _wrapper
return bound_func(*args, **kwargs)
File "/home/travis/virtualenv/python2.7.12/lib/python2.7/site-packages/django/contrib/auth/decorators.py", line 23, in _wrapped_view
return view_func(request, *args, **kwargs)
File "/home/travis/virtualenv/python2.7.12/lib/python2.7/site-packages/django/utils/decorators.py", line 63, in bound_func
return func.__get__(self, type(self))(*args2, **kwargs2)
File "/home/travis/virtualenv/python2.7.12/lib/python2.7/site-packages/django/utils/decorators.py", line 67, in _wrapper
return bound_func(*args, **kwargs)
File "/home/travis/virtualenv/python2.7.12/lib/python2.7/site-packages/django/contrib/auth/decorators.py", line 23, in _wrapped_view
return view_func(request, *args, **kwargs)
File "/home/travis/virtualenv/python2.7.12/lib/python2.7/site-packages/django/utils/decorators.py", line 63, in bound_func
return func.__get__(self, type(self))(*args2, **kwargs2)
File "/home/travis/build/deltaskelta/langalang/define/views.py", line 21, in dispatch
return super(Define, self).dispatch(*args, **kwargs)
File "/home/travis/virtualenv/python2.7.12/lib/python2.7/site-packages/django/views/generic/base.py", line 88, in dispatch
return handler(request, *args, **kwargs)
File "/home/travis/build/deltaskelta/langalang/define/views.py", line 89, in post
return upload_audio(request, context)
File "/home/travis/build/deltaskelta/langalang/define/views_func.py", line 251, in upload_audio
make_mp3(mp3_path, request.FILES['audio_file'])
File "/home/travis/build/deltaskelta/langalang/define/views_func.py", line 25, in make_mp3
['lame', '-', '--comp', '40', path], stdin=PIPE, stdout=PIPE, stderr=PIPE)
File "/opt/python/2.7.12/lib/python2.7/subprocess.py", line 711, in __init__
errread, errwrite)
File "/opt/python/2.7.12/lib/python2.7/subprocess.py", line 1343, in _execute_child
raise child_exception
OSError: [Errno 2] No such file or directory
我不明白爲什麼這會通過我的系統上測試和失敗的構建。輸入文件顯然存在,因爲request.FILES
找到它。該目錄存在..我檢查。那麼它是什麼告訴我不存在?
如果您在生產時手動執行它(如果可以的話)會怎麼樣?事情是,這個例外可以不參考路徑參數,但要命令你執行 – valignatev
你發佈這個權利,因爲我想通了。我忘了在編譯環境中安裝跛腳。你怎麼知道這也可能是問題?我花了幾個小時一次又一次地檢查路徑,因爲我認爲這就是它告訴我 – deltaskelta
我試圖在答案中解釋它。 – valignatev