Power BI is turning 10! Tune in for a special live episode on July 24 with behind-the-scenes stories, product evolution highlights, and a sneak peek at what’s in store for the future.
Save the dateEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.
Hi,
I am having trouble with this endpoint. I am able to authenticate but having no luck with sending up a .whl file.
I keep getting this error:
"EnvironmentValidationFailed","message":"Invalid request. Provide a library with a valid format such as .jar, .py, .whl, .tar.gz, or environment.yml."
I am using python w/requests, I feel like it could be something simple with how I am sending the file or maybe with my headers?
Any help appreciated.
Solved! Go to Solution.
Hi Yang,
I was able to get it working using this:
headers = {
'Authorization': f"Bearer {token}"
#It worked with no other headers
}
url = 'https://api.fabric.microsoft.com/v1/workspaces/{workspace_id}/environments/{environment_id}/staging/libraries'
file_path = "file_path"
with open(file_path,'rb') as file:
files = {'file':(os.path.basename(file_path),file)}
response = requests.post(url,files=files,
headers = headers)
if response.status_code == 200:
print(f'Success: {response.json}')
else:
print(f'Failure: {response.status_code} {response.text}')
Thanks for your help!
Hi @jaskiea ,
Try this:
import requests
headers = {
'Authorization': f"Bearer {token}",
'Content-Type': 'multipart/form-data',
'Content-Length': str(os.path.getsize(file_path)) # Add Content-Length header
}
url = 'https://api.fabric.microsoft.com/v1/workspaces/{workspace_id}/environments/{environment_id}/staging/libraries'
file_path = "file_path"
with open(file_path, 'rb') as file:
files = {'file': (os.path.basename(file_path), file)} # Add filename
response = requests.post(url, files=files, headers=headers)
if response.status_code == 200:
print(f'Success: {response.json()}')
else:
print(f'Failure: {response.status_code} {response.text}')
Add Content-Length to the original code to specify the file size, added filename.
If you have any other questions please feel free to contact me.
Best Regards,
Yang
Community Support Team
If there is any post helps, then please consider Accept it as the solution to help the other members find it more quickly.
If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!
Hi Yang,
I was able to get it working using this:
headers = {
'Authorization': f"Bearer {token}"
#It worked with no other headers
}
url = 'https://api.fabric.microsoft.com/v1/workspaces/{workspace_id}/environments/{environment_id}/staging/libraries'
file_path = "file_path"
with open(file_path,'rb') as file:
files = {'file':(os.path.basename(file_path),file)}
response = requests.post(url,files=files,
headers = headers)
if response.status_code == 200:
print(f'Success: {response.json}')
else:
print(f'Failure: {response.status_code} {response.text}')
Thanks for your help!
Hi @jaskiea ,
I am glad to hear that your problem has been resolved.
I am very thankful to you for sharing your solution which will be of great help to other users who are experiencing similar issues.
Could you please mark this helpful post as “Answered”?
Thank you for your cooperation!
Best Regards,
Yang
Community Support Team
If there is any post helps, then please consider Accept it as the solution to help the other members find it more quickly.
If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!
Hi
Thank you for your response.
Yes I made sure it was a legitamate whl file, I also tried a simple .py file and that failed the validation as well.
I am still wondering if there could be a simple issue with how I am sending the request.
headers = {
'Authorization': f"Bearer {token}"
,'Content-Type':'multipart/form-data'
}
url = 'https://api.fabric.microsoft.com/v1/workspaces/{workspace_id}/environments/{environment_id}/staging/libraries'
file_path = "file_path"
with open(file_path,'rb') as file:
files = {'file':file}
response = requests.post(url,files=files,
headers = headers)
if response.status_code == 200:
print(f'Success: {response.json}')
else:
print(f'Failure: {response.status_code} {response.text}')
Here's my code. I have tested other environment call and authentication works.
Thanks,
Adam
Hi @jaskiea ,
The error message indicates that the request is invalid, please provide the file in the correct format.
I have the following suggestions:
Here is an official document you can refer to that may help:
Spark Libraries - Upload Staging Library - REST API (Environment) | Microsoft Learn
Best Regards,
Yang
Community Support Team
If there is any post helps, then please consider Accept it as the solution to help the other members find it more quickly.
If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!
This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.
Check out the June 2025 Fabric update to learn about new features.
User | Count |
---|---|
4 | |
4 | |
3 | |
2 | |
2 |