Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AttributeError: 'datetime.timezone' object has no attribute 'zone' #68

Closed
yusuftanmc opened this issue May 21, 2021 · 11 comments
Closed
Labels
bug Something isn't working in DEV Resolution is in DEV release

Comments

@yusuftanmc
Copy link

  • 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

@patrik-eriksson
Copy link

I have the exact same issue. 😞

@dshore
Copy link
Collaborator

dshore commented May 24, 2021

Looking into this...

@dshore
Copy link
Collaborator

dshore commented May 24, 2021

@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"

@patrik-eriksson
Copy link

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'

@dshore
Copy link
Collaborator

dshore commented May 24, 2021

@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}

@patrik-eriksson
Copy link

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}

@patrik-eriksson
Copy link

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.

@dshore
Copy link
Collaborator

dshore commented May 24, 2021

@patrik-eriksson I was able to reproduce issue. Looking into it.

@dshore dshore added the bug Something isn't working label May 24, 2021
@dshore
Copy link
Collaborator

dshore commented May 24, 2021

dshore added a commit that referenced this issue May 25, 2021
Update timezone for writing to GAM (#68)
@dshore dshore added the in DEV Resolution is in DEV release label May 25, 2021
@dshore
Copy link
Collaborator

dshore commented May 25, 2021

@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

@dshore
Copy link
Collaborator

dshore commented May 26, 2021

Refactored this here:
#70

This is much cleaner; creating a new custom datetime class that is used by yaml constructor and representer.

@dshore dshore closed this as completed May 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working in DEV Resolution is in DEV release
Projects
None yet
Development

No branches or pull requests

3 participants