cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Anonymous
Not applicable

Python script error in Power Query Editor PythonUnexpectedException

Hello, 

I'm working on a Power BI report. I have multiple queries in the Power Query Editor including Python scripts. Suddenly some scripts that did work previously, now give the following error: 

 

DataSource.Error: ADO.NET: A problem occurred while processing your Python script.
Here are the technical details: [Expression.Error] We cannot return a value of type Table in this context.
Details:
DataSourceKind=Python
DataSourcePath=Python
Message=A problem occurred while processing your Python script.
Here are the technical details: [Expression.Error] We cannot return a value of type Table in this context.
ErrorCode=-2147467259
ExceptionType=Microsoft.PowerBI.Scripting.Python.Exceptions.PythonUnexpectedException

 

Other scripts still work fine. The same simple Python script that works in some queries, does not work for other queries. Any ideas what could be the cause for this, and how to fix it?

My python version is 3.7 (64-bit), and my Microsoft Power BI Desktop version is 2.70.5494.562 64-bit (June 2019).

 

Thanks for your help!
 
Rianne

1 ACCEPTED SOLUTION
v-frfei-msft
Community Support
Community Support

Hi @Anonymous ,

 

From the Data Source Settings dialog, select the data source(s) and then select Edit Permissions... and ensure that the Privacy Level is set to Public.

 

 

Community Support Team _ Frank
If this post helps, then please consider Accept it as the solution to help the others find it more quickly.

View solution in original post

5 REPLIES 5
v-frfei-msft
Community Support
Community Support

Hi @Anonymous ,

 

From the Data Source Settings dialog, select the data source(s) and then select Edit Permissions... and ensure that the Privacy Level is set to Public.

 

 

Community Support Team _ Frank
If this post helps, then please consider Accept it as the solution to help the others find it more quickly.

I met this same problem but can fix by solution here.

my code:

import re
hours_lst = []
for s in zip(dataset['timeSpent']):
    p = re.compile("(?P<day>\d+d)?\s*(?P<hour>\d+h)?\s*(?P<minute>\d+m)?")
    m = re.search(p, str(s))
    day = m.group('day') 
    day = re.findall("\d+", day)[0] if day else 0
    hour = m.group('hour')
    hour = re.findall("\d+", hour)[0] if hour else 0
    minute = m.group('minute')
    minute = re.findall("\d+", minute)[0] if minute else 0
    hours = 8*int(day) + int(hour) + float(minute)/60
    hours_lst.append(0)                    
dataset['hours'] = hours_lst

Hi All, unfortunately i have the same problem since installing the June 2019 Power BI  update and changing the data source's privacy level to public did not fix the problem.   I appreciate any additional support anyone has on this issue. 

C:\Users\YouUSER\Anaconda3
C:\Users\YouUSER\Anaconda3\Library\mingw-w64\bin
C:\Users\YouUSER\Anaconda3\Scripts
C:\Users\YouUSER\Anaconda3\Library\bin

Anonymous
Not applicable

That works, thanks a lot!

Helpful resources

Announcements
collabdays lisbon

CollabDays Lisbon - 26 November 2022

Sessions include practical, hands-on experience that will help you take the next step in your career and know-how.

Difinity Conference

Difinity Conference 2022

Difinity is the largest Microsoft Data, AI, Power BI, Power Platform and Business Applications Conference in New Zealand.

European Share Point Conference

European Share Point Conference

This conference returns live and in-person in Copenhagen this 28 November-01 December with 4 Microsoft Keynotes, 9 Tutorials, and 120 Sessions.

Microsoft 365 Conference â__ December 6-8, 2022

Microsoft 365 Conference - 06-08 December

Join us in Las Vegas to experience community, incredible learning opportunities, and connections that will help grow skills, know-how, and more.