pdonorio / angulask

A project to template flask web server to meet angularjs
0 stars 0 forks source link

Unable to call API from Flask #18

Closed mdantonio closed 8 years ago

mdantonio commented 8 years ago

I'm trying to perform an API call from Flask via Request library to implement the three-way login schema as discussed (angularjs -> flask_frontend -> flask_api)

I'm able to perform request get/post calls to any external resource (google, github, etc) but i'm not able to call API:

This request remains stuck just until a timeout request.get('http://130.186.13.86:8081/login')

requests.exceptions.Timeout: HTTPConnectionPool(host='130.186.13.86', port=8081): Read timed out. (read timeout=5)

from inside the flask docker machine the call works with no problem via curl

curl -X GET http://130.186.13.86:8081/login

pdonorio commented 8 years ago

I will test the problem on docker from a container to another. The first container will be running the API and the second via link will launch a Python request to those API login endpoint

pdonorio commented 8 years ago

(next time copy/paste the snippet of request :P)

pdonorio commented 8 years ago

This works for me:

import requests
import simplejson as json

URL = 'http://%s:%s' % (NODE, PORT)
LOGIN_URL = URL + '/login'
HEADERS = {'content-type': 'application/json'}
payload = {'email': USER, 'password': PW}
r = requests.post(LOGIN_URL, data=json.dumps(payload), headers=HEADERS)

print(r, r.url)
print("RESPONSE:")
try:
    print(r.json())
except:
    print(r.text)

Check if it works for you too and we can close the issue.

mdantonio commented 8 years ago

I modified the API call implementation to reflect your own version... but i get the same "read timed out" exception... maybe some difference that i'm not able to see...

pdonorio commented 8 years ago

The problem was related to who you are calling.

You have to set your /mylogin endpoint inside Flask Frontend, not Flask API.

pdonorio commented 8 years ago

Not the real workflow