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
dbeavon3
Memorable Member
Memorable Member

Error when getting the workspace name from a notebook

I'm just trying to get the workspace name from a workbook with notebookutils and it is choking and dying.
This error happens when running the notebook as a service principal.


this_workspace_name = notebookutils.mssparkutils.env.getWorkspaceName()

... Results in:

Py4JJavaError: An error occurred while calling z:mssparkutils.env.getWorkspaceName.
: org.apache.http.client.HttpResponseException: status code: 403

 

dbeavon3_0-1753149103858.png

 

 

org.apache.http.client.HttpResponseException: status code: 403, reason phrase: Non HTTP 200 response code. StatusCode=403 Reason=Forbidden

2 REPLIES 2
v-hashadapu
Community Support
Community Support

Hi @dbeavon3 , Thank you for reaching out to the Microsoft Community Forum.

 

This is happening because notebookutils.mssparkutils.env.getWorkspaceName() makes an internal API call to fetch workspace metadata, which service principals can’t access by default. In Microsoft Fabric, service principals don’t have implicit rights to read workspace context, this includes the workspace name, even if they have access to the Lakehouse or notebooks.

 

To resolve it, go to the Fabric workspace and assign the service principal a Contributor or Admin role at the workspace level via the access control settings. This gives it the necessary control plane permissions to access metadata APIs used by that utility function.

 

If updating permissions isn’t an option, inject the workspace name into the notebook manually using a parameter or environment variable. This avoids the API call entirely and works reliably in service principal contexts.

Hi @v-hashadapu 

Do you have a reference/link with that information?  Is there a known issue?  Is it by design?  I don't think it is true that service principals are restricted, as compared to normal users.  It has not been my experience.

FYI, The service principals are already full admins.


This may be a bug.  I found some other related discussions on another forum, but it was quite old (maybe a year?)  Is it possible that this sort of bug would remain unfixed for another year?  If so, I think Microsoft should provide some documentation about this bug in the meantime.  Perhaps they should use their "known issues" list.

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

June FBC25 Carousel

Fabric Monthly Update - June 2025

Check out the June 2025 Fabric update to learn about new features.