Search code examples
qtcurlqt4qt5qprocess

QProcess curl and the github REST api


I'm trying to use the GitHub REST API to create an issue in a repo. I'm using the following command:

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

This works perfectly as expected. However, when I use QProcess to execute the same command, I get {"message": "Bad credentials", "documentation_url": "https://developer.github.com/v3"}

This is how I use QProcess (Python/Qt4 2.7.14/4.12.1 on Debian Sid):

>>> 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()

Is there some mistake I am doing?


Solution

  • The problem is caused by the quotes around your credentials(''), it is not necessary to use them if they are at the beginning and end of the argument.

    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()