1

I'm trying to use the Github Markdown API to turn Markdown files into pretty HTML files but I can't seem to get the API to work.

I've been using requests.post with payloads exactly as detailed in the documentation here and I've tried changing a few things but nothing seems to return the HTML that I want.

Here is the code I'm using:

import requests

with open("index.md", "r") as markdown, open("index.html", "w") as html:
    payload = {"text": markdown.read(), "mode": "markdown"}
    html.write(requests.post("https://api.github.com/markdown", data=payload).text)

The return from the Github API is the following:

{
    "message": "Problems parsing JSON",
    "documentation_url": "https://developer.github.com/v3/markdown/#render-an-arbitrary-markdown-document"
}

where an HTML version of my document is expected back.

1 Answer 1

3

Since the API was expecting json the request should have been:

html.write(requests.post("https://api.github.com/markdown", json=payload).text)

Which uses json instead of data to send the payload with the post request.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.