localhost refused to connect - worked initially, but not anymore

I have an AWS EC2 instance with Windows Server 2019. I installed python (with pip) and then created a python venv and in it installed prodigy and the jupyterlab extension, essentially everything as per Github instructions at (GitHub - explosion/jupyterlab-prodigy: 🧬 A JupyterLab extension for annotating data with Prodigy).

I downloaded the 'news_headlines.jsonl' file and in one terminal in my prodigy venv started the command 'prodigy ner.manual my_set blank:en notebooks/news_headlines.jsonl --label PERSON,ORG,PRODUCT', although I changed the location of the news_headlines file.

Then I started a second terminal and I don't remember if I started outside or inside the venv, but I believe I copied one of the links from Jupyter lab and then I believe I started chrome and pasted the link. I looked for prodigy in Jupyter Lab was able to see the news_headlines file before in Jupyter Lab.

It worked.

I terminated all the windows and wanted to restart as above, but now when jupyter labs starts, I get 'localhost refused to connect.'

I have Jupyter Server 1.18.1 running.
The following is a snippet from the log once jupyter lab is executed:
[I 2022-09-13 15:04:05.878 ServerApp] http://localhost:8888/lab?token=97c2 etc etc.

Now, the chrome browser automatically starts, but I run into this client - server connection issue.

Ping to localhost and both work.

Anyone have any idea how to resolve this?

hi @rstr!

Thanks for your question and welcome to Prodigy community :wave:

Just to clarify, are you getting the localhost refused to connect error when your run jupyter lab to start Jupyter or when you try to run a prodigy recipe like python -m prodigy ...? Or easier, if you can provide more details on the output.

It's not clear yet if the problem is jupyter lab, Prodigy, or the jupyterlab-prodigy.

Can you run in a terminal and provide output (this will give your Prodigy version):

python -m prodigy stats

This will at least confirm that Prodigy was installed. I don't think this is the problem but I want to rule it out. Btw, it's best to prefix prodigy commands with python -m.

If you can run Jupyter Lab, can you try to run a prodigy recipe within a notebook instead (i.e., run your prodigy recipe with a ! in a notebook chunk):

If Prodigy doesn't automatically open, can you create a new tab for the Launcher (like at the bottom) and try to open Prodigy by clicking the Open Prodigy button as shown here:

Let me know if either of these work. There are more potential issues but this will at least diagnose the basics.

Also, if you haven't already, I'd recommend looking at other Prodigy Support issues on the same keywords "localhost refused" or by the tag jupyter.

Hi Ryan, thanks for the reply and ideas to troubleshoot.

Regarding your first question, when the error occurs, I follow to two steps as in GitHub. So, in the first terminal, I get into my venv, and then I execute the slightly modified "prodigy ner.manual my_set blank:en notebooks/news_headlines.jsonl --label PERSON,ORG,PRODUCT" command, only modified to point to the right location of the json file. Then in another window I start Jupiter lab, which automatically starts my chrome browser and I assume wants to connect to the Jupiter server and execute the recipe.

Here's the output of the stats command of course running it in the venv: You can see I have it all installed as an admin and (this time - yes, I deleted the venv with everything and then recreated it to see if that would help, but no) my venv is called prodigy:

(prodigy) PS C:\Users\Administrator\Projects> python -m prodigy stats

============================== :sparkles: Prodigy Stats ==============================

Version 1.11.8
Location C:\Users\Administrator\Projects\prodigy\lib\site-packages\prodigy
Prodigy Home C:\Users\Administrator.prodigy
Platform Windows-10-10.0.17763-SP0
Python Version 3.10.6
Database Name SQLite
Database Id sqlite
Total Datasets 1
Total Sessions 1

On your third point, when I just go into Jupyter Lab and execute the same command above or the variation in your gif, nothing happens. It just progresses to the next line. In the terminal where I started Jupiter lab all I see is this:

[I 2022-09-14 08:39:27.844 ServerApp] Saving file at /prodigy/Untitled.ipynb

This is in the file:
"cells": [
"cell_type": "markdown",
"id": "4c4cc71e-1a56-4303-9b52-9c10e12d89ab",
"metadata": {},
"source": [
"!python -m prodigy ner.teach test news_headlines.jsonl --label PERSON,ORG,PRODUCT"
"cell_type": "code",
"execution_count": null,
"id": "a9632bce-272f-405d-ac97-bba58f1e303f",
"metadata": {},
"outputs": ,
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.6"
"nbformat": 4,
"nbformat_minor": 5

Sorry, I forgot to respond to the last idea. The Open Prodigy icon and Open Prodigy Docs icon are there, but when I click Open Prodigy, it opens a prodigy tab but the message is the same, localhost refused to connect.

hi @rstr!

Thanks for the background.

That's good that Prodigy was installed correctly so you can begin using Prodigy via terminal.

Someone had success with to modify the host on the prodigy.json to "":

If this is successful, then you will want to follow these instructions to modify your prodigyConfig:

Last, could there be some AWS firewall or rules to modify?

If this doesn't help, since you were able to get it to run one time, it may be worth a try to rebuild your instance. Hopefully it isn't too inconvenient.

Let us know if you come up on any further questions or if you're able to get this to work!

Dear Ryan,

Thanks again for your assistance.

Well, I got it working, again. :slight_smile:

I did not keep super great notes, or I have not connected all the dots yet, but I think this is what I did this time:

  1. When we use the command line to start the (default) recipe in the python virtual environment, I now start with python -m and then followed by prodigy etc etc. We need to ensure that we see this first terminal hung up, i.e., we do not want to see the prompt blinking for a new command entry. I had the latter problem, but no more.

  2. In the second terminal where we type in Jupyter lab, this time I did it outside the virtual environment. I am a bit baffled. I installed it inside the virtual environment. I may have started this way the first time I got it working, too, I don’t quite remember. This terminal should also be in hung up mode, and this server keeps printing/logging actions from people in Jupyter lab to the command line, which is very useful.

  3. And when the browser automatically starts, it wants to point to ‘localhost’, but it seems we need to replace this with, or copy that second suggested link from the second terminal where we started jupyter lab.

  4. I played with that port number in Jupyter Lab itself, I think I changed it twice, but I am not sure that did anything.

One little note: I suspect I have an educational version of prodigy. The prodigy.json (you call it config.json) file is empty.

For now, I am good.

Best regards

That's great. I'm glad it worked.

By default Prodigy won't have a prodigy.json (yep, it's technically a prodigy.json yet it is a config file and I accidentally called it config.json). But if it's missing, Prodigy will use these default settings here. This is why it's typically a good practice to create this file so you can be explicit about what configuration settings. Just mentioning for others who find this post.