plaid/quickstart

Python backend: Unable to fetch link_token

pccampbell opened this issue · 4 comments

Hello I have been trying and failing to get the backend working in Python for some time now. My .env file is fine and I have been able to get the backend going and the front end connected if I use node and start it that way with no problems. When I try to run python server.py it shows that it is running on port 8000, but when I run npm start from frontend folder I get the "Unable to fetch link_token". When that happens I also don't see anything new in the backend terminal window at all. Not sure why this would work fine in node, but fail in python. Want to be able to utilize the code and develop in Python. Let me know if you need any more info.

@pccampbell this means that the call to /link/token/create couldn't succeed. A couple of things you should look at:

Check the developer console in the frontend -- are there any errors there?
Any errors in the terminal window where you are running the python server?
Any errors on https://dashboard.plaid.com/activity/logs?

IIRC the last time someone ran into this it was because they had not run the python setup steps / had not installed the latest version of the plaid python client libraries, so make sure to check that as well. it's easy to accidentally skip the setup steps if you've already run them for another language.

@phoenixy1 Front end terminal doesn't show any issues. The terminal running the python backend does not show any errors either (it shows nothing after starting) which I think is odd I would have maybe expected to see an error here after starting the front end. Similarly the dashboard does not show any logs when running the front and and getting the "Unable to fetch link_token" error in http://localhost:3000/.

I'm not sure exactly what setup steps you are referring to. The repo was cloned with symlinks, .env setup with keys and 'sandbox' for environment, and the requirements installed in my virtual environment from requirements.txt. Then in front end I ran npm install and npm start. If I am missing a step here please let me know. I also tried upgrading plaid-python from the version in requirements.txt (9 to 11) but that did not help.

In chrome developers console I see that create_link_token and info have 504 errors, which makes it seem to me like it doesn't even see the backend server for some reason. Very stumped, hope I'm not missing something silly. Thanks for the help

So last night I noticed that the python backend specifically calls out that it is "running on http://127.0.0.1:8000". I honestly didn't think there would be a practical difference of this from "localhost", but I thought I would try to switch the front end to explicitly point to that instead of http://localhost:8000. Not super familiar with the front end code but I changed it in two places "packages.json" and "setupProxy.js" and it was finally able to connect. Intuition told me that it couldn't see the backend at all, but am not knowledgeable enough to pick up that functionally those two would be different. Hopefully this thread can help anyone who has a similar issue and if someone wants to add a note in the quickstart docs somewhere that might be helpful too. Thanks @phoenixy1 for the initial response.

Thanks, @pccampbell !

Belated follow-up: This happens for people using node 17 and later because node now defaults to looking for the ipv6 version of localhost instead of the ipv4 version, which is what the server code is using. (More details here) I'm guessing there are probably a more sophisticated fixes out there that involve changing the default behavior to prefer ipv4 addresses, but honestly, explicitly specifying an ipv4 address like 127.0.0.1 is a lot easier.