So I am testing my web service with HTTpie and I am trying to issue a GET request with the following
http --json --auth <ADMIN_EMAIL>:<PASSWORD> GET http://127.0.0.1:5000/api/v1.0/posts
Removed actual email and password to post here
@api.route('/posts/')
def get_posts():
page = request.args.get('page', 1, type=int)
pagination = Post.query.paginate(
page, per_page=current_app.config['POSTS_PER_PAGE'],
error_out=False)
posts = pagination.items
prev = None
if pagination.has_prev:
prev = url_for('api.get_posts', page=page-1, _external=True)
next = None
if pagination.has_next:
next = url_for('api.get_posts', page=page+1, _external=True)
return jsonify({
'posts': [post.to_json() for post in posts],
'prev': prev,
'next': next,
'count': pagination.total
})
api is a blueprint
And I am getting the following error
http: error: ConnectionError: ('Connection aborted.', error(111, 'Connection refused'))
Going to http://
127.0.0.1/api/v.10/posts` in a browser does work, but it's not clear what's different between the browser and httpie.
Okay so my virtualenv was on python 2.7 and by upgrading it to python 3.4 it seemed to do the trick and have successfully connected!