I tried to replicate the error you are getting. I copied your code and replaced the endpoint and credential key. I just ran it in the terminal it is working perfectly fine. You can check this!
From what I see, you do not have sufficient access or privilege to access that resource. That is the issue.