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
juan_pablo
Advocate III
Advocate III

Python visual requieres to open a file in the service

Hi everyone!

I have a python visual in my Power BI Desktop report, the script for this visual opens a python .pkl file to run a small model and with the results it generate the final plot (a simple plt.scatter) to be displayed in the report. Everything works fine in the PBI Desktop version on my local machine (the script opens the pkl file, runs the model and generates the plot in the PBI report), but when I upload the report to the server, for obvious reasons, the python script can't find the .pkl file required.

How can I make available the pkl file in the server so that the visual script can open it, generate the final plot and therefore the visual in the report?

 

I tried with a personal gateway but it seems it only works to access the .csv files for the data model in my local machine, but not the files required by a python script on a visual, or I don't know how to configure it properly.

 

Can you please help me in order to solve this?

Thanks in advance.!

9 REPLIES 9
v-yingjl
Community Support
Community Support

Hi @juan_pablo ,

If you've fixed the issue on your own please kindly share your solution. If the above posts help, please kindly mark it as a solution to help others find it more quickly. Thanks!


Best Regards,
Yingjie Li

Hi @v-yingjl 

 

No, unfortunately I haven't found a solution. 

I decided to open the file from an S3 in AWS (Amazon) as @lbendlin  suggested. This work great in the Desktop version, but as soon as I publish the report to the Service, it breaks.

Your solution didn't work for me because I still need to have interactivity in the visual (I need other filters to affect the visual because they are the input to the model).

 

@lbendlin Do you know how to make the connection to the web server accessible from Power BI Service?

 

This is a summary of what I have so far:

 

link = "https://xxxxxx.s3.amazonaws.com/models/linear_model_v1.pkl"
def predict_sq_meter_value(apartments): 
    try: 
        lin_model_v0
    except: 
        lin_model_v0 = pickle.load(urllib.request.urlopen(link))

...

 

The last line "pickle.load(urllib.request.urlopen(link))" is the one that breaks when published to the PBI Service, but in the Desktop  works as expected.

 

This is the error I get in the published report

 

URL Error in the Server.png

 

 

Script Runtime Error
    self._send_request(method, url, body, headers, encode_chunked)
  File "C:\Python\Lib\http\client.py", line 1298, in _send_request
    self.endheaders(body, encode_chunked=encode_chunked)
  File "C:\Python\Lib\http\client.py", line 1247, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
  File "C:\Python\Lib\http\client.py", line 1026, in _send_output
    self.send(msg)
  File "C:\Python\Lib\http\client.py", line 966, in send
    self.connect()
  File "C:\Python\Lib\http\client.py", line 1414, in connect
    super().connect()
  File "C:\Python\Lib\http\client.py", line 938, in connect
    (self.host,self.port), self.timeout, self.source_address)
  File "C:\Python\Lib\socket.py", line 707, in create_connection
    for res in getaddrinfo(host, port, 0, SOCK_STREAM):
  File "C:\Python\Lib\socket.py", line 752, in getaddrinfo
    for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno 11001] getaddrinfo failed

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Script\0.py", line 92, in <module>
    sq_val, tot_val = predict_sq_meter_value(property)
  File "C:\Script\0.py", line 39, in predict_sq_meter_value
    lin_model_v0 = pickle.load(urllib.request.urlopen(link))
  File "C:\Python\Lib\urllib\request.py", line 222, in urlopen
    return opener.open(url, data, timeout)
  File "C:\Python\Lib\urllib\request.py", line 525, in open
    response = self._open(req, data)
  File "C:\Python\Lib\urllib\request.py", line 543, in _open
    '_open', req)
  File "C:\Python\Lib\urllib\request.py", line 503, in _call_chain
    result = func(*args)
  File "C:\Python\Lib\urllib\request.py", line 1362, in https_open
    context=self._context, check_hostname=self._check_hostname)
  File "C:\Python\Lib\urllib\request.py", line 1321, in do_open

    raise URLError(err)

urllib.error.URLError: <urlopen error [Errno 11001] getaddrinfo failed>


Please try again later or contact support. If you contact support, please provide these details.
Activity ID: 28e08314-3838-462e-b4ec-5de753c8fb15
Request ID: 80f03bdf-612e-aa34-1a41-e45de7239e1a
Correlation ID: f0bea7a5-a996-d6a4-6786-0c24eecfbb45
Time: Tue Jul 28 2020 10:39:59 GMT-0500 (Colombia Standard Time)
Service version: 13.0.13960.55
Client version: 2007.3.02011-train
Cluster URI: https://wabi-south-central-us-redirect.analysis.windows.net/

 

 

Any ideas on how can I solve this? I think I'm very close.

The service doesn't know how to reach the file on AWS. maybe an authentication issue?

 

For fun you could try this on the gateway to see if you get a different error message there.  (yes, I know, gateway isn't really required)

@lbendlin  The AWS is running ok, in fact I can acces the pkl file from my PBI Desktop file using the same code or using any python console.

 

What do you mean by "try this on the gateway"? 

I already have a gateway installed and connected to the report.

 

gateway connection.png

 

Ah, it's a personal gateway.  I forgot that Python/R need that. Ignore me.

lbendlin
Super User
Super User

Find a solution that doesn't require the .pkl file.

@lbendlin  like which one?
I tried to place the whole code in the visual but that causes that the model gets trained every time a slicer or filter is selected (a query is made), and I already have the model pre trained.

Do you have another way to do it without the pickle file? or any place I can read about similar solutions?

Hi @juan_pablo ,

'I tried to place the whole code in the visual but that causes that the model gets trained every time a slicer or filter is selected (a query is made), and I already have the model pre trained.'

So you want the python visual retain the initial status that no affected by slicer and filter right?

One solution is that you can try to use 'edit interactions' to diable the interactions between python visual and slicers.

 

  • In the Power BI service, open the report in Editing view and select the dropdown from the report menu bar.

         interact.png

Refer this document: Change how visuals interact in a Power BI report 

 

Best Regards,
Yingjie Li

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

Try masquerading the .pkl as a binary resource, or place it on a web server that is accessible from Power BI Service.

Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

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

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 community update carousel

Fabric Community Update - June 2025

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