Forum Discussion
API create-semantic-model error ""Parts: Must be a non-empty collection with no null elements""
- 8 months ago
I think I've figured it out - it's annoying.
The python requests.post() has two possible inputs (well, three if you include params). The usual one is 'data' and it expects a dict. The other is 'json', which also expects a dict-like structure, but coerces it into application/json.
(note I tried data = json.dumps(payload) and got an invalid media error) - 8 months ago
spencer_sa So the issue was in the Content-Type Header,Right?
It should be
Content-Type: application/jsonand the correct usage should be like that:
response = requests.post( url, json=payload_dict, # <-- correct headers={ "Authorization": f"Bearer {token}", "Content-Type": "application/json" } )
spencer_sa So the issue was in the Content-Type Header,Right?
It should be
Content-Type: application/jsonand the correct usage should be like that:
response = requests.post(
url,
json=payload_dict, # <-- correct
headers={
"Authorization": f"Bearer {token}",
"Content-Type": "application/json"
}
)As long as you use the following
json=payload_dict
you don't need the Content-Type as it coerces that by using the 'json' input, but yes.
This is what helped me - about half way down.
https://requests.readthedocs.io/en/latest/user/quickstart/
It's annoying as the error message is a complete red herring.
- Ahmed-Elfeel8 months agoSuper User
Ok mark your answer/replys as a solution to help other
This was usfel thanks for sharing☺️❤️