QProcess curl和github REST api

时间:2018-03-28 06:06:27

标签: qt curl qt4 qt5 qprocess

我尝试使用GitHub REST API在回购中创建问题。我使用以下命令:

curl -u "marcusbritanicus:pass" https://api.github.com/repos/marcusbritanicus/apitrial/issues -XPOST -H 'Content-Type: application/json' -d@issue.json

这完全符合预期。但是,当我使用QProcess执行相同的命令时,我得到{"message": "Bad credentials", "documentation_url": "https://developer.github.com/v3"}

这就是我使用QProcess(Debian Sid上的Python / Qt4 2.7.14 / 4.12.1)的方法:

>>> proc = QProcess()
>>> proc.setProcessChannelMode( QProcess.MergedChannels )
>>> args = [ "-u", "'marcusbritanicus:password'", "https://api.github.com/repos/marcusbritanicus/apitrial/issues", "-XPOST", "-H", "'Content-Type: application/json'", "-d@issue.json" ]
>>> proc.start( "curl", args )
>>> proc.waitForFinished()
>>> proc.readAll()

我在做什么错误?

1 个答案:

答案 0 :(得分:1)

问题是由您的凭据('')周围的引号引起的,如果它们位于参数的开头和结尾,则无需使用它们。

proc = QProcess()
proc.setProcessChannelMode( QProcess.MergedChannels )
args = [ "-u", "marcusbritanicus:password", "https://api.github.com/repos/marcusbritanicus/apitrial/issues", "-XPOST", "-H", "Content-Type: application/json", "-d@issue.json" ]
proc.start( "curl", args )
proc.waitForFinished()
proc.readAll()