最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

python - Error Creating Job in YouTube Reporting API - Stack Overflow

programmeradmin4浏览0评论

I'm following the API referenced here but nothing I am doing seems to be working. Below is my code and the error message I am getting

import requests
access_token = 'MY_ACCESS_TOKEN'

headers = {
    "content-type": "application/x-www-form-urlencoded",
    "Authorization": f"Bearer {access_token}",
}
url = ";
data = {
    "reportTypeId": "channel_basic_a2",
    "name": "my_job",
}
response = requests.post(url, headers=headers, data=data)
# Also tried
# response = requests.post(url, headers=headers, params=data)
assert response.status_code == 200, f"{response.status_code} {response.text}"
print(response.text)

Below is the error message I am getting

"error": {
    "code": 400,
    "message": "Invalid JSON payload received. Unknown name \"reportTypeId\": Cannot bind query parameter. Field 'reportTypeId' could not be found in request message.\nInvalid JSON payload received. Unknown name \"name\": Cannot bind query parameter. Field 'name' could not be found in request message.",
    "status": "INVALID_ARGUMENT",
    "details": [
      {
        "@type": "type.googleapis/google.rpc.BadRequest",
        "fieldViolations": [
          {
            "description": "Invalid JSON payload received. Unknown name \"reportTypeId\": Cannot bind query parameter. Field 'reportTypeId' could not be found in request message."
          },
          {
            "description": "Invalid JSON payload received. Unknown name \"name\": Cannot bind query parameter. Field 'name' could not be found in request message."
          }
        ]
      }
    ]
  }

I'm following the API referenced here but nothing I am doing seems to be working. Below is my code and the error message I am getting

import requests
access_token = 'MY_ACCESS_TOKEN'

headers = {
    "content-type": "application/x-www-form-urlencoded",
    "Authorization": f"Bearer {access_token}",
}
url = "https://youtubereporting.googleapis/v1/jobs"
data = {
    "reportTypeId": "channel_basic_a2",
    "name": "my_job",
}
response = requests.post(url, headers=headers, data=data)
# Also tried
# response = requests.post(url, headers=headers, params=data)
assert response.status_code == 200, f"{response.status_code} {response.text}"
print(response.text)

Below is the error message I am getting

"error": {
    "code": 400,
    "message": "Invalid JSON payload received. Unknown name \"reportTypeId\": Cannot bind query parameter. Field 'reportTypeId' could not be found in request message.\nInvalid JSON payload received. Unknown name \"name\": Cannot bind query parameter. Field 'name' could not be found in request message.",
    "status": "INVALID_ARGUMENT",
    "details": [
      {
        "@type": "type.googleapis/google.rpc.BadRequest",
        "fieldViolations": [
          {
            "description": "Invalid JSON payload received. Unknown name \"reportTypeId\": Cannot bind query parameter. Field 'reportTypeId' could not be found in request message."
          },
          {
            "description": "Invalid JSON payload received. Unknown name \"name\": Cannot bind query parameter. Field 'name' could not be found in request message."
          }
        ]
      }
    ]
  }
Share Improve this question asked Mar 21 at 18:30 Arthur BeyerArthur Beyer 1 3
  • Did you try to retrieve the reportTypeId in your report types list? Try to get request in your reportTypes to get the valid reportTypeId developers.google/youtube/reporting/v1/reference/rest/v1/… – Jason V. Castellano Commented Mar 21 at 18:48
  • @JasonV.Castellano yes I tried that and it worked. channel_basic_a2 is one of the reportTypeIds returned – Arthur Beyer Commented Mar 21 at 20:17
  • There is somthing wrong in sending your request, Just check your content-type": "application/x-www-form-urlencoded" just try application/json because you are sending a json object in your server. There is an error: Field 'name' could not be found in request message. it means the name in your attributes cannot be found. – Jason V. Castellano Commented Mar 21 at 20:30
Add a comment  | 

1 Answer 1

Reset to default 0

I think, there's something wrong with your request. Check your header "content-type" is set to "application/x-www-form-urlencoded" , but since you're sending a JSON object, try to switch it to application/json. As you can see , the error Cannot bind query parameter. Field 'name' could not be found in request message.", attribute is missing , it means there something wrong in sending request in your server.

发布评论

评论列表(0)

  1. 暂无评论