How to fix the PyVis Knowledge Graph error: localhost refused to connect
If you’re trying to build a knowledge graph, you might be using PyVis, which is a fast way to generate visual network graphs using Python. You can use PyVis in Jupyter Notebooks, locally, or in my case, generate the graphs as HTML files and then visualize those.
❌ The Problem
If you’re trying to run your code, you might run into a number of issues, such as localhost refused to connect
like what is shown below:
✅ The Solution
By importing and leveraging the HTML
and display
modules from IPython.core, we can then add this extra line to display the knowledge graph with: display(HTML(filename='example.html'))
Check out the code and the output below:
Looking for more resources?
Read more related content here:
- Automating Code Generation with OpenAI GPT Agents: A Developer's Journey to Efficiency
- Thankful for the AWS Community Builders Program & Building + AWS Step Functions 101
- AWS: Predicting Stock Prices Using AI & NO CODE!
- Want to Learn How to Code? Discover the Top 4 Platforms to Kickstart Your Software Engineer Journey of Coding
- Turn Your AI Model into a Real Product (Amazon SageMaker, API Gateway, AWS Lambda, Next.js, Python)
- Launch your own LLM (Deploy LLaMA 2 on Amazon SageMaker with Hugging Face Deep Learning Containers)
Snag my 7 Days of Development ebook here:
I'll send you a FREE copy of my 7 Days of Development Ebook to get you started writing Python scripts, Node.js functions, Next.js apps, and building in the cloud!