【问题标题】:django error returned non-zero exit status 1django 错误返回非零退出状态 1
【发布时间】:2017-03-29 13:13:16
【问题描述】:

我正在将一个文件从 Django 网站上传到我的 WordPress。

from subprocess import check_call
    try:
        check_call(['scp', filename, upload_filename])
         ....
    except (CalledProcessError, OSError):
        report['error_messages'].append("4 %s" % exc_info()[1])
        return report

这给出了错误:

命令'['scp', '/uploads/test-01.txt', 'mysite.com:/home/wp-content/uploads/test-01.txt']' 返回非零 退出状态 1

现在, 如果我从控制台手动操作:

scp /uploads/test-01.txt mysite.com:/home/wp-content/uploads/test-01.txt

它正在工作:

test-01.txt  100% 0  0.0KB/s 00:00

(这是一个空文件,所以 0 KB)

我不明白为什么 scp 从 Django 失败。错误不清楚。我能做什么?

【问题讨论】:

  • 尝试在文件中放入一行文本,会发生同样的事情吗?
  • @postoronnim 你是什么意思?

标签: python django


【解决方案1】:

如果您暂时将代码更改为使用check_output 而不是check_call,则可以捕获标准错误。

from subprocess import check_output, CalledProcessError, STDOUT

try:
    check_output(['scp', filename, upload_filename], stderr=STDOUT)
except CalledProcessError as e:
    print(e.output)  # output from STDERR should show what is going wrong

这应该会提示您出了什么问题。如果在控制台中测试命令时 Django 网站以与您不同的用户身份运行,则可能是权限。

【讨论】:

  • 当我添加这个时,什么也没有发生。它甚至没有显示以前的错误。我的 django 已经很老了,可能有关系吗?
  • 如果 Django 没有记录 print 语句,您可能必须更改它,否则 Django 的版本应该没有区别。以上代码均来自 Python 标准库。
  • 我改成如下:from subprocess import check_call,check_output, CalledProcessError, STDOUT try: check_output(['scp', filename, upload_filename],stderr=STDOUT) .... except (CalledProcessError, OSError): report['error_messages'].append("4 %s, %s" % (CalledProcessError.output ,exc_info()[1])) return report 什么也没有发生,它似乎不知道该怎么做...
  • 这与我上面的代码非常不同。您没有像我一样将异常分配给变量e - except CalledProcessError as e:。然后您的代码尝试访问 CalledProcessError.outpute.output
  • 同样的事情。什么都没发生。我什么都没看到。
猜你喜欢
  • 2017-05-20
  • 1970-01-01
  • 1970-01-01
  • 2014-01-13
  • 2019-10-02
  • 1970-01-01
  • 2014-07-30
  • 1970-01-01
  • 2017-12-11
相关资源
最近更新 更多