LoginSignup
0
0

More than 1 year has passed since last update.

Azure REST Api "InvalidResource"erro解決

Last updated at Posted at 2023-03-30

Azure Media ServiceのAPIを呼び出していた際、

400 {
  "error": {
    "code": "InvalidResource",
    "message": "The resource format is invalid."
  }
}

のエラーが発生し、調べても同じ事例が見つからず手こずってしまったので解決策を投稿いたします。
またほぼ同じ環境で

400 {
  "error": {
    "code": "InvalidResource",
    "message": "Invalid JSON. A token was not recognized in the JSON content."
  }
}

こちらのエラーも発生していたので参考になればと思います。

前提条件
Python3.10でrequestモジュールを使用しApi呼び出しを行っている。

エラー事象

Mediaserviceのアセットの、SASを含むURLを発行するためのApiを呼び出しています。
az.py
import request

url="https://management.azure.com/subscriptions/********/resourceGroups/hogehoge/providers/Microsoft.Media/mediaServices/hogehoge/assets/hogehoge/listContainerSas?api-version=2022-08-01"
headers = {
    'Content-Type': 'application/json',
    'Authorization': f'Bearer {token}',
}
payload = {
"permissions": "ReadWrite",
"expiryTime": "2018-01-01T10:00:00.007Z"
}
response = requests.post(url, data=payload,headers=headers, )
print(response.status_code, response.text)

すると結果は

400 {
  "error": {
    "code": "InvalidResource",
    "message": "The resource format is invalid."
  }
}

となります。

解決策

az.py
response = requests.post(url, json=payload,headers=headers, )

第一引数をjsonとしたところうまく動きました。どうやらリクエストボディがjson形式として認識されていなかったようです。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0