Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.
Register now!Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.
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 ,
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!
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 ,
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!
| User | Count |
|---|---|
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |