Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Anonymous
Not applicable

Error Reading image from public URL using python visual

Hi,

 

I want to add a background image to a scatter plot with some arrows and the only way I could think of doing it in python. However, I am having an issue with it. My code runs fine on Jupyter notebook and on Power BI Desktop, but does not work when published to Power BI service. Please see the details down below.

 

 

Sample Python Script down below (only for showing image with no scatter plot):

# The following code to create a dataframe and remove duplicated rows is always executed and acts as a preamble for your script:

# dataset = pandas.DataFrame(x,y)
# dataset = dataset.drop_duplicates()

# Paste or type your script code here:
import matplotlib.pyplot as plt

ax = plt.gca()

image_path = '<png_image_url>'
img = plt.imread(image_path)
ax.imshow(img, extent = [0, 2000, 0, 2000])

plt.show()
 
 
When published to Power BI service, I am getting a script runtime error with details below:
Script Runtime Error
During handling of the above exception, another exception occurred: urllib.error.URLError: <urlopen error [WinError 10050] A socket operation encountered a dead network>
Please try again later or contact support. If you contact support, please provide these details.
 
 
5 REPLIES 5
Eraclea
New Member

Hi, I am also encounterning problem of importing images, but from local files. How did you import the local images to power bi with python script?

v-henryk-mstf
Community Support
Community Support

Hi @Anonymous ,

 

For your description, you can refer to similar solutions:

How do I read image data from a URL in Python? - Stack Overflow

 

In addition, I think it is also a good way to obtain images of web pages in power query. Refer to the content of this blog:

Get Images from Web Page Into the Power BI Report Using Power Query - RADACAD


If the problem is still not resolved, please provide detailed error information and let me know immediately. Looking forward to your reply.


Best Regards,
Henry


If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Anonymous
Not applicable

Hi Henry,

 

Thank you for your reply. Unfortunately, none of the methods suggested worked. One of our user request was to build some traffic flow analysis with image as a background, which should be able to dynamically change when selecting different location on the slicers. I am unable to find any built-in visuals on Power BI which can do this, thus I had to use Python to build a custom visual from matplotlib.

 

Best Regards,

lunastra

amitchandak
Super User
Super User

@Anonymous , Is that a local image path - image_path = '<png_image_url>'

 

If yes, try to use some web image url and check 

 

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube
Anonymous
Not applicable

Hi amitchandak,

 

thank you for the quick reply. This is a web image url that I can also access through my web browser.

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

Find out what's new and trending in the Fabric community.

July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.

Top Solution Authors