Python script to query REST API and write to database
Some suggestions:


A linter (or two) such as pycodestyle or flake8 will help you write more idiomatic Python. For example, brackets are not required around an if statement.
You can use query_posts_response.json() to easily get JSON response content.
I can't see a reason why this script should do anything with the input and output streams.
db_connection.close() should be in a finally block. The try block should start with creating the connection.
If you ever intend to reuse the code it should be wrapped inside at least a main function (which orchestrates argument parsing, handling exceptions which should lead to non-zero return codes, and the like) and a separate function to do the work.