AttributeError: 'datetime.timezone' object has no attribute 'zone'
yusuftanmc opened this issue · 11 comments
- line-item-manager version: 0.2.2
- Python version: 3.8.3
- Operating System: Mac OS 11.3
Description
Failed attempt to create line items on GAM using line-item-manager
What I Did
When I used the --dry-run flag, it was successful.
line_item_manager create <yml config file> --dry-run --private-key-file <privatekey.json> --bidder-code appnexus
But when I removed the flag
line_item_manager create <yml config file> --private-key-file <privatekey.json> --bidder-code appnexus
I encountered this error message:
line 413, in AdManagerDateTimePacker 'timeZoneId': value.tzinfo.zone,
AttributeError: 'datetime.timezone' object has no attribute 'zone'
config file:
demo_line_item_manager.yml.zip
error trace:
error.log
I have the exact same issue. 😞
Looking into this...
@yusuftanmc, @patrik-eriksson
I am not able to reproduce this error.
I get the following when running with the provided config:
$ line_item_manager create issue.yml -b appnexus -n -t
Usage: line_item_manager create [OPTIONS] CONFIGFILE
Try 'line_item_manager create --help' for help.
Error: Unknown Time Zone, 'SG'
"SG" is a country code. I changed the following to use the TZ database name and it ran w/o incident:
line_item:
timezone: "Asia/Singapore"
Hi @dshore
Many thanks for looking into this.
I have the timezone set to Europe/Oslo
but still, get the error. Here are my yml-file. Can the date settings on my computer have an effect on this? It has not the same format as in the YAML.
[2861893327]
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.9/bin/line_item_manager", line 8, in <module>
sys.exit(main())
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/line_item_manager/cli.py", line 162, in main
cli() # pylint: disable=no-value-for-parameter
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/click/core.py", line 829, in __call__
return self.main(*args, **kwargs)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/click/core.py", line 782, in main
rv = self.invoke(ctx)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/click/core.py", line 1259, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/click/core.py", line 1066, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/click/core.py", line 610, in invoke
return callback(*args, **kwargs)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/click/decorators.py", line 21, in new_func
return f(get_current_context(), *args, **kwargs)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/line_item_manager/cli.py", line 128, in create
gam.create_line_items()
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/line_item_manager/gam_config.py", line 276, in create_line_items
self._lica_objs.append(li_.create())
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/line_item_manager/gam_config.py", line 104, in create
for line_item in self.line_items:
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/line_item_manager/gam_config.py", line 165, in line_items
self._line_items = LineItem().create(recs, validate=True)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/line_item_manager/gam_operations.py", line 42, in create
getattr(self.svc(), self.create_method)(atts)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/googleads/common.py", line 989, in MakeSoapRequest
packed_args = self._PackArguments(method_name, args)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/googleads/common.py", line 850, in _PackArguments
result = [self._PackArgumentsHelper(param, param_data, set_type_attrs)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/googleads/common.py", line 850, in <listcomp>
result = [self._PackArgumentsHelper(param, param_data, set_type_attrs)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/googleads/common.py", line 905, in _PackArgumentsHelper
packed_result = [self._PackArgumentsHelper(elem, item, set_type_attrs)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/googleads/common.py", line 905, in <listcomp>
packed_result = [self._PackArgumentsHelper(elem, item, set_type_attrs)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/googleads/common.py", line 895, in _PackArgumentsHelper
packed_result = self._CreateComplexTypeFromData(
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/googleads/common.py", line 957, in _CreateComplexTypeFromData
instantiated_arguments = {
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/googleads/common.py", line 958, in <dictcomp>
k: self._PackArgumentsHelper(elem_arguments[k], v, set_type_attrs)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/googleads/common.py", line 884, in _PackArgumentsHelper
data = self._packer.Pack(data, self._version)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/googleads/ad_manager.py", line 388, in Pack
return cls.AdManagerDateTimePacker(obj, version)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/googleads/ad_manager.py", line 413, in AdManagerDateTimePacker
'timeZoneId': value.tzinfo.zone,
AttributeError: 'datetime.timezone' object has no attribute 'zone'
@patrik-eriksson Can you run with "-v -v". We might be able to debug this from logs like this:
VERBOSE1:line_item_manager.gam_config:line_item:
{'end_datetime': '05/29/21 00:01',
'end_dt': datetime.datetime(2021, 5, 29, 0, 1, tzinfo=datetime.timezone(datetime.timedelta(seconds=2580))),
'goal': {'goalType': 'NONE'},
'item_type': 'price_priority',
'name': 'Test: Prebid Automation Demo-AppNexus-banner-05/24/2021-11:12:14 @ '
'0.10',
'priority': 12,
'start_datetime': '05/26/21 00:01',
'start_dt': datetime.datetime(2021, 5, 26, 0, 1, tzinfo=datetime.timezone(datetime.timedelta(seconds=2580))),
'start_dt_type': 'USE_START_DATE_TIME',
'timezone': 'Europe/Oslo',
'unlimited_end_dt': False}
Thanks. I get this, looks ok?
VERBOSE1:line_item_manager.gam_config:line_item:
{'end_datetime': '05/29/21 00:01',
'end_dt': datetime.datetime(2021, 5, 29, 0, 1, tzinfo=datetime.timezone(datetime.timedelta(seconds=2580))),
'goal': {'goalType': 'NONE'},
'item_type': 'price_priority',
'name': 'TEST - Prebid-AppNexus-banner-05/24/2021-17:41:58 @ 3.00',
'priority': 12,
'start_datetime': '05/26/21 00:01',
'start_dt': datetime.datetime(2021, 5, 26, 0, 1, tzinfo=datetime.timezone(datetime.timedelta(seconds=2580))),
'start_dt_type': 'USE_START_DATE_TIME',
'timezone': 'Europe/Oslo',
'unlimited_end_dt': False}
Hi again,
I solved it by hardcoding in Europe/Oslo in ad_manager.py
Everything looks ok and managed to create everything without any issues.
@patrik-eriksson I was able to reproduce issue. Looking into it.
Bug Description:
This is stripping out the zone name:
https://github.com/prebid/line-item-manager/blob/master/line_item_manager/template.py#L57
which is required here:
https://github.com/googleads/googleads-python-lib/blob/master/googleads/ad_manager.py#L416
Potential solution:
Need to refactor this code to be run after template rendering:
https://github.com/prebid/line-item-manager/blob/master/line_item_manager/config.py#L164
@patrik-eriksson I released a fix to dev.
Can you try again after getting the dev version?
$ pip uninstall line-item-manager
$ pip install https://github.com/prebid/line-item-manager/archive/master.zip
$ line_item_manager --version
line-item-manager version 0.2.2-dev3