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
|
1 Answer
Reset to default 0I 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.
content-type": "application/x-www-form-urlencoded"
just tryapplication/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 thename
in your attributes cannot be found. – Jason V. Castellano Commented Mar 21 at 20:30