-
-
Notifications
You must be signed in to change notification settings - Fork 73
Description
Describe the bug
I encountered a problem when trying to utilize the create_negative_keywords method from the Amazon Ads API library in Sponsored Brands Ads. Specifically, a ValueError: too many values to unpack (expected 2) is raised during the process of encoding parameters in the requests library. Other methods like list_negative_keywords work flawlessly, suggesting the problem is localized to the create_negative_keywords method.
Library version
python-amazon-ad-api==0.5.0
To Reproduce
def add_neg_kw_simple():
payload = [
{
"adGroupId": 1234567890,
"campaignId": 1234567890,
"keywordText": "some kw text",
"matchType": "negativeExact",
}
]
try:
result = sb.NegativeKeywords(
marketplace=Marketplaces.NA, credentials=my_credentials
).create_negative_keywords(body=payload)
print(result)
except AdvertisingApiException as e:
print(e)
add_neg_kw_simple()
Console Output
Traceback (most recent call last):
File "/Users/some/path/negative_kw_add.py", line 501, in <module>
add_neg_kw_simple()
File "/Users/some/path/negative_kw_add.py", line 491, in add_neg_kw_simple
result = sb.NegativeKeywords(
File "/opt/miniconda3/envs/amazon-ads/lib/python3.9/site-packages/ad_api/base/helpers.py", line 21, in wrapper
return function(*args, **kwargs)
File "/opt/miniconda3/envs/amazon-ads/lib/python3.9/site-packages/ad_api/api/sb/negative_keywords.py", line 76, in create_negative_keywords
return self._request(kwargs.pop('path'), data=kwargs.pop('body'), params=kwargs)
File "/opt/miniconda3/envs/amazon-ads/lib/python3.9/site-packages/ad_api/base/client.py", line 255, in _request
res = request(
File "/opt/miniconda3/envs/amazon-ads/lib/python3.9/site-packages/requests/api.py", line 59, in request
return session.request(method=method, url=url, **kwargs)
File "/opt/miniconda3/envs/amazon-ads/lib/python3.9/site-packages/requests/sessions.py", line 573, in request
prep = self.prepare_request(req)
File "/opt/miniconda3/envs/amazon-ads/lib/python3.9/site-packages/requests/sessions.py", line 484, in prepare_request
p.prepare(
File "/opt/miniconda3/envs/amazon-ads/lib/python3.9/site-packages/requests/models.py", line 371, in prepare
self.prepare_body(data, files, json)
File "/opt/miniconda3/envs/amazon-ads/lib/python3.9/site-packages/requests/models.py", line 559, in prepare_body
body = self._encode_params(data)
File "/opt/miniconda3/envs/amazon-ads/lib/python3.9/site-packages/requests/models.py", line 121, in _encode_params
for k, vs in to_key_val_list(data):
ValueError: too many values to unpack (expected 2)
Desktop:
- OS: MacOS Ventura
- Version 13.5.2
Additional context
This error seems to arise when the requests library tries to encode the payload data.
As aforementioned, other methods (e.g., list_negative_keywords) work without issues, which indicates this issue is exclusive to the create_negative_keywords function.
I kindly ask for guidance on how to resolve this issue or any potential workarounds.
Thank you for your assistance!