gramsch
gramsch

Reputation: 399

"Problems parsing JSON" when creating an issue with github API and Python requests

When I try to create an issue with the python requests module, it returns the problem {"message":"Problems parsing JSON","documentation_url":"https://developer.github.com/v3"}

here is the code I use:

user = <My user>
pswd = <My password>
ses = requests.Session()
ses.auth = (user, pswd)
issue = {"title": "Hello World",
         "body": "omg",
         "assignee": <My user>,
         "milestone": None,
"labels": ["label", "friend"]
}
l = json.dumps(issue)
r = ses.post("https://api.github.com/repos/<My user>/<My repo>", params=l)

Of course I replaced the things in <> for the actual user and repo, I put it like that here for privacy reasons

Upvotes: 0

Views: 2174

Answers (1)

Bertrand Martel
Bertrand Martel

Reputation: 45352

Use json parameter to send JSON document and POST to /repos/:owner/:repo/issues :

import requests
import json

user = "username"
pswd = "password"
repo = "your-repo"

ses = requests.Session()
ses.auth = (user, pswd)

issue = {
    "title": "Hello World",
    "body": "omg",
    "assignee": user,
    "milestone": None,
    "labels": ["label", "friend"]
}

issue_url = "https://api.github.com/repos/" + user + "/" + repo + "/issues"

r = ses.post(issue_url, json = issue)

Upvotes: 2

Related Questions