AttributeError: module 'dateutil.tz' has no attribute 'UTC' on Zappa Deploy
AttributeError: module 'dateutil.tz' has no attribute 'UTC' on Zappa Deploy
在尝试部署我的 AWS Lambda 函数时,在我的 Stacktrace 上收到此错误
(python-dateutil 2.8.1 (/Users/supratik/.local/share/virtualenvs/api_sourcer-sM-JSZy3-/Users/supratik/.pyenv/shims/python/lib/python3.6/site-packages), Requirement.parse('python-dateutil<2.7.0'), {'zappa'})
Calling deploy for stage development..
Oh no! An error occurred! :(
==============
Traceback (most recent call last):
File "/Users/supratik/.local/share/virtualenvs/api_sourcer-sM-JSZy3-/Users/supratik/.pyenv/shims/python/lib/python3.6/site-packages/zappa/cli.py", line 2778, in handle
sys.exit(cli.handle())
File "/Users/supratik/.local/share/virtualenvs/api_sourcer-sM-JSZy3-/Users/supratik/.pyenv/shims/python/lib/python3.6/site-packages/zappa/cli.py", line 512, in handle
self.dispatch_command(self.command, stage)
File "/Users/supratik/.local/share/virtualenvs/api_sourcer-sM-JSZy3-/Users/supratik/.pyenv/shims/python/lib/python3.6/site-packages/zappa/cli.py", line 549, in dispatch_command
self.deploy(self.vargs['zip'])
File "/Users/supratik/.local/share/virtualenvs/api_sourcer-sM-JSZy3-/Users/supratik/.pyenv/shims/python/lib/python3.6/site-packages/zappa/cli.py", line 709, in deploy
self.zappa.create_iam_roles()
File "/Users/supratik/.local/share/virtualenvs/api_sourcer-sM-JSZy3-/Users/supratik/.pyenv/shims/python/lib/python3.6/site-packages/zappa/core.py", line 2557, in create_iam_roles
role, credentials_arn = self.get_credentials_arn()
File "/Users/supratik/.local/share/virtualenvs/api_sourcer-sM-JSZy3-/Users/supratik/.pyenv/shims/python/lib/python3.6/site-packages/zappa/core.py", line 2536, in get_credentials_arn
self.credentials_arn = role.arn
File "/Users/supratik/.local/share/virtualenvs/api_sourcer-sM-JSZy3-/Users/supratik/.pyenv/shims/python/lib/python3.6/site-packages/boto3/resources/factory.py", line 339, in property_loader
self.load()
File "/Users/supratik/.local/share/virtualenvs/api_sourcer-sM-JSZy3-/Users/supratik/.pyenv/shims/python/lib/python3.6/site-packages/boto3/resources/factory.py", line 505, in do_action
response = action(self, *args, **kwargs)
File "/Users/supratik/.local/share/virtualenvs/api_sourcer-sM-JSZy3-/Users/supratik/.pyenv/shims/python/lib/python3.6/site-packages/boto3/resources/action.py", line 83, in __call__
response = getattr(parent.meta.client, operation_name)(**params)
File "/Users/supratik/.local/share/virtualenvs/api_sourcer-sM-JSZy3-/Users/supratik/.pyenv/shims/python/lib/python3.6/site-packages/botocore/client.py", line 316, in _api_call
return self._make_api_call(operation_name, kwargs)
File "/Users/supratik/.local/share/virtualenvs/api_sourcer-sM-JSZy3-/Users/supratik/.pyenv/shims/python/lib/python3.6/site-packages/botocore/client.py", line 613, in _make_api_call
operation_model, request_dict, request_context)
File "/Users/supratik/.local/share/virtualenvs/api_sourcer-sM-JSZy3-/Users/supratik/.pyenv/shims/python/lib/python3.6/site-packages/botocore/client.py", line 632, in _make_request
return self._endpoint.make_request(operation_model, request_dict)
File "/Users/supratik/.local/share/virtualenvs/api_sourcer-sM-JSZy3-/Users/supratik/.pyenv/shims/python/lib/python3.6/site-packages/botocore/endpoint.py", line 102, in make_request
return self._send_request(request_dict, operation_model)
File "/Users/supratik/.local/share/virtualenvs/api_sourcer-sM-JSZy3-/Users/supratik/.pyenv/shims/python/lib/python3.6/site-packages/botocore/endpoint.py", line 135, in _send_request
request, operation_model, context)
File "/Users/supratik/.local/share/virtualenvs/api_sourcer-sM-JSZy3-/Users/supratik/.pyenv/shims/python/lib/python3.6/site-packages/botocore/endpoint.py", line 167, in _get_response
request, operation_model)
File "/Users/supratik/.local/share/virtualenvs/api_sourcer-sM-JSZy3-/Users/supratik/.pyenv/shims/python/lib/python3.6/site-packages/botocore/endpoint.py", line 218, in _do_get_response
response_dict, operation_model.output_shape)
File "/Users/supratik/.local/share/virtualenvs/api_sourcer-sM-JSZy3-/Users/supratik/.pyenv/shims/python/lib/python3.6/site-packages/botocore/parsers.py", line 242, in parse
parsed = self._do_parse(response, shape)
File "/Users/supratik/.local/share/virtualenvs/api_sourcer-sM-JSZy3-/Users/supratik/.pyenv/shims/python/lib/python3.6/site-packages/botocore/parsers.py", line 509, in _do_parse
parsed = self._parse_shape(shape, start)
File "/Users/supratik/.local/share/virtualenvs/api_sourcer-sM-JSZy3-/Users/supratik/.pyenv/shims/python/lib/python3.6/site-packages/botocore/parsers.py", line 302, in _parse_shape
return handler(shape, node)
File "/Users/supratik/.local/share/virtualenvs/api_sourcer-sM-JSZy3-/Users/supratik/.pyenv/shims/python/lib/python3.6/site-packages/botocore/parsers.py", line 377, in _handle_structure
member_shape, member_node)
File "/Users/supratik/.local/share/virtualenvs/api_sourcer-sM-JSZy3-/Users/supratik/.pyenv/shims/python/lib/python3.6/site-packages/botocore/parsers.py", line 302, in _parse_shape
return handler(shape, node)
File "/Users/supratik/.local/share/virtualenvs/api_sourcer-sM-JSZy3-/Users/supratik/.pyenv/shims/python/lib/python3.6/site-packages/botocore/parsers.py", line 377, in _handle_structure
member_shape, member_node)
File "/Users/supratik/.local/share/virtualenvs/api_sourcer-sM-JSZy3-/Users/supratik/.pyenv/shims/python/lib/python3.6/site-packages/botocore/parsers.py", line 302, in _parse_shape
return handler(shape, node)
File "/Users/supratik/.local/share/virtualenvs/api_sourcer-sM-JSZy3-/Users/supratik/.pyenv/shims/python/lib/python3.6/site-packages/botocore/parsers.py", line 175, in _get_text_content
return func(self, shape, text)
File "/Users/supratik/.local/share/virtualenvs/api_sourcer-sM-JSZy3-/Users/supratik/.pyenv/shims/python/lib/python3.6/site-packages/botocore/parsers.py", line 462, in _handle_timestamp
return self._timestamp_parser(text)
File "/Users/supratik/.local/share/virtualenvs/api_sourcer-sM-JSZy3-/Users/supratik/.pyenv/shims/python/lib/python3.6/site-packages/botocore/utils.py", line 626, in parse_timestamp
return _parse_timestamp_with_tzinfo(value, tzinfo)
File "/Users/supratik/.local/share/virtualenvs/api_sourcer-sM-JSZy3-/Users/supratik/.pyenv/shims/python/lib/python3.6/site-packages/botocore/utils.py", line 607, in _parse_timestamp_with_tzinfo
return dateutil.parser.parse(value, tzinfos={'GMT': tzutc()})
File "/Users/supratik/.local/share/virtualenvs/api_sourcer-sM-JSZy3-/Users/supratik/.pyenv/shims/python/lib/python3.6/site-packages/dateutil/parser/_parser.py", line 1374, in parse
return DEFAULTPARSER.parse(timestr, **kwargs)
File "/Users/supratik/.local/share/virtualenvs/api_sourcer-sM-JSZy3-/Users/supratik/.pyenv/shims/python/lib/python3.6/site-packages/dateutil/parser/_parser.py", line 660, in parse
ret = self._build_tzaware(ret, res, tzinfos)
File "/Users/supratik/.local/share/virtualenvs/api_sourcer-sM-JSZy3-/Users/supratik/.pyenv/shims/python/lib/python3.6/site-packages/dateutil/parser/_parser.py", line 1201, in _build_tzaware
aware = naive.replace(tzinfo=tz.UTC)
AttributeError: module 'dateutil.tz' has no attribute 'UTC'
==============```
尝试使用 aws cli 从 AWS S3 复制文件时遇到类似问题。 运行 pip install python-dateutil
将 python-dateutil 更新为 2.8.1,现在运行良好。
python -m pip install --upgrade python-dateutil
升级python-dateutil
解决了我的问题。在我的机器上,2.5.3
到 2.8.1
。
略读源码,发现在2.7.0
中添加了UTC
变量。所以,我认为任何版本 >= 2.7.0
都可以解决问题。
#: Convenience constant providing a :class:`tzutc()` instance
#:
#: .. versionadded:: 2.7.0
UTC = tzutc()
尝试指定 python-dateutil 版本并将其安装在有错误的包之前,在您的情况下为 zappa
示例:
pip install python-dateutil==2.8.1 zappa
我的情况是我收到错误的包裹是 freezegun,所以我 运行
pip install python-dateutil==2.8.1 freezegun==0.3.15
成功了
我在尝试 运行 eb deploy
AWS Elastic Beanstalk 时遇到了这个问题。
对我有用的是: sudo pip3 install python-dateutil --upgrade
(注意:运行在没有 sudo 的情况下执行此操作无法解决问题)
作为参考,这是我在此之前遇到的错误:
eb deploy projectFoo
Deploying to development environment
Deploying to AWS
Creating application version archive "app-200711_113503".
Uploading projectFoo/app-200711_113503.zip to S3. This may take a while.
Upload Complete.
ERROR: AttributeError - module 'dateutil.tz' has no attribute 'UTC'
在尝试部署我的 AWS Lambda 函数时,在我的 Stacktrace 上收到此错误
(python-dateutil 2.8.1 (/Users/supratik/.local/share/virtualenvs/api_sourcer-sM-JSZy3-/Users/supratik/.pyenv/shims/python/lib/python3.6/site-packages), Requirement.parse('python-dateutil<2.7.0'), {'zappa'})
Calling deploy for stage development..
Oh no! An error occurred! :(
==============
Traceback (most recent call last):
File "/Users/supratik/.local/share/virtualenvs/api_sourcer-sM-JSZy3-/Users/supratik/.pyenv/shims/python/lib/python3.6/site-packages/zappa/cli.py", line 2778, in handle
sys.exit(cli.handle())
File "/Users/supratik/.local/share/virtualenvs/api_sourcer-sM-JSZy3-/Users/supratik/.pyenv/shims/python/lib/python3.6/site-packages/zappa/cli.py", line 512, in handle
self.dispatch_command(self.command, stage)
File "/Users/supratik/.local/share/virtualenvs/api_sourcer-sM-JSZy3-/Users/supratik/.pyenv/shims/python/lib/python3.6/site-packages/zappa/cli.py", line 549, in dispatch_command
self.deploy(self.vargs['zip'])
File "/Users/supratik/.local/share/virtualenvs/api_sourcer-sM-JSZy3-/Users/supratik/.pyenv/shims/python/lib/python3.6/site-packages/zappa/cli.py", line 709, in deploy
self.zappa.create_iam_roles()
File "/Users/supratik/.local/share/virtualenvs/api_sourcer-sM-JSZy3-/Users/supratik/.pyenv/shims/python/lib/python3.6/site-packages/zappa/core.py", line 2557, in create_iam_roles
role, credentials_arn = self.get_credentials_arn()
File "/Users/supratik/.local/share/virtualenvs/api_sourcer-sM-JSZy3-/Users/supratik/.pyenv/shims/python/lib/python3.6/site-packages/zappa/core.py", line 2536, in get_credentials_arn
self.credentials_arn = role.arn
File "/Users/supratik/.local/share/virtualenvs/api_sourcer-sM-JSZy3-/Users/supratik/.pyenv/shims/python/lib/python3.6/site-packages/boto3/resources/factory.py", line 339, in property_loader
self.load()
File "/Users/supratik/.local/share/virtualenvs/api_sourcer-sM-JSZy3-/Users/supratik/.pyenv/shims/python/lib/python3.6/site-packages/boto3/resources/factory.py", line 505, in do_action
response = action(self, *args, **kwargs)
File "/Users/supratik/.local/share/virtualenvs/api_sourcer-sM-JSZy3-/Users/supratik/.pyenv/shims/python/lib/python3.6/site-packages/boto3/resources/action.py", line 83, in __call__
response = getattr(parent.meta.client, operation_name)(**params)
File "/Users/supratik/.local/share/virtualenvs/api_sourcer-sM-JSZy3-/Users/supratik/.pyenv/shims/python/lib/python3.6/site-packages/botocore/client.py", line 316, in _api_call
return self._make_api_call(operation_name, kwargs)
File "/Users/supratik/.local/share/virtualenvs/api_sourcer-sM-JSZy3-/Users/supratik/.pyenv/shims/python/lib/python3.6/site-packages/botocore/client.py", line 613, in _make_api_call
operation_model, request_dict, request_context)
File "/Users/supratik/.local/share/virtualenvs/api_sourcer-sM-JSZy3-/Users/supratik/.pyenv/shims/python/lib/python3.6/site-packages/botocore/client.py", line 632, in _make_request
return self._endpoint.make_request(operation_model, request_dict)
File "/Users/supratik/.local/share/virtualenvs/api_sourcer-sM-JSZy3-/Users/supratik/.pyenv/shims/python/lib/python3.6/site-packages/botocore/endpoint.py", line 102, in make_request
return self._send_request(request_dict, operation_model)
File "/Users/supratik/.local/share/virtualenvs/api_sourcer-sM-JSZy3-/Users/supratik/.pyenv/shims/python/lib/python3.6/site-packages/botocore/endpoint.py", line 135, in _send_request
request, operation_model, context)
File "/Users/supratik/.local/share/virtualenvs/api_sourcer-sM-JSZy3-/Users/supratik/.pyenv/shims/python/lib/python3.6/site-packages/botocore/endpoint.py", line 167, in _get_response
request, operation_model)
File "/Users/supratik/.local/share/virtualenvs/api_sourcer-sM-JSZy3-/Users/supratik/.pyenv/shims/python/lib/python3.6/site-packages/botocore/endpoint.py", line 218, in _do_get_response
response_dict, operation_model.output_shape)
File "/Users/supratik/.local/share/virtualenvs/api_sourcer-sM-JSZy3-/Users/supratik/.pyenv/shims/python/lib/python3.6/site-packages/botocore/parsers.py", line 242, in parse
parsed = self._do_parse(response, shape)
File "/Users/supratik/.local/share/virtualenvs/api_sourcer-sM-JSZy3-/Users/supratik/.pyenv/shims/python/lib/python3.6/site-packages/botocore/parsers.py", line 509, in _do_parse
parsed = self._parse_shape(shape, start)
File "/Users/supratik/.local/share/virtualenvs/api_sourcer-sM-JSZy3-/Users/supratik/.pyenv/shims/python/lib/python3.6/site-packages/botocore/parsers.py", line 302, in _parse_shape
return handler(shape, node)
File "/Users/supratik/.local/share/virtualenvs/api_sourcer-sM-JSZy3-/Users/supratik/.pyenv/shims/python/lib/python3.6/site-packages/botocore/parsers.py", line 377, in _handle_structure
member_shape, member_node)
File "/Users/supratik/.local/share/virtualenvs/api_sourcer-sM-JSZy3-/Users/supratik/.pyenv/shims/python/lib/python3.6/site-packages/botocore/parsers.py", line 302, in _parse_shape
return handler(shape, node)
File "/Users/supratik/.local/share/virtualenvs/api_sourcer-sM-JSZy3-/Users/supratik/.pyenv/shims/python/lib/python3.6/site-packages/botocore/parsers.py", line 377, in _handle_structure
member_shape, member_node)
File "/Users/supratik/.local/share/virtualenvs/api_sourcer-sM-JSZy3-/Users/supratik/.pyenv/shims/python/lib/python3.6/site-packages/botocore/parsers.py", line 302, in _parse_shape
return handler(shape, node)
File "/Users/supratik/.local/share/virtualenvs/api_sourcer-sM-JSZy3-/Users/supratik/.pyenv/shims/python/lib/python3.6/site-packages/botocore/parsers.py", line 175, in _get_text_content
return func(self, shape, text)
File "/Users/supratik/.local/share/virtualenvs/api_sourcer-sM-JSZy3-/Users/supratik/.pyenv/shims/python/lib/python3.6/site-packages/botocore/parsers.py", line 462, in _handle_timestamp
return self._timestamp_parser(text)
File "/Users/supratik/.local/share/virtualenvs/api_sourcer-sM-JSZy3-/Users/supratik/.pyenv/shims/python/lib/python3.6/site-packages/botocore/utils.py", line 626, in parse_timestamp
return _parse_timestamp_with_tzinfo(value, tzinfo)
File "/Users/supratik/.local/share/virtualenvs/api_sourcer-sM-JSZy3-/Users/supratik/.pyenv/shims/python/lib/python3.6/site-packages/botocore/utils.py", line 607, in _parse_timestamp_with_tzinfo
return dateutil.parser.parse(value, tzinfos={'GMT': tzutc()})
File "/Users/supratik/.local/share/virtualenvs/api_sourcer-sM-JSZy3-/Users/supratik/.pyenv/shims/python/lib/python3.6/site-packages/dateutil/parser/_parser.py", line 1374, in parse
return DEFAULTPARSER.parse(timestr, **kwargs)
File "/Users/supratik/.local/share/virtualenvs/api_sourcer-sM-JSZy3-/Users/supratik/.pyenv/shims/python/lib/python3.6/site-packages/dateutil/parser/_parser.py", line 660, in parse
ret = self._build_tzaware(ret, res, tzinfos)
File "/Users/supratik/.local/share/virtualenvs/api_sourcer-sM-JSZy3-/Users/supratik/.pyenv/shims/python/lib/python3.6/site-packages/dateutil/parser/_parser.py", line 1201, in _build_tzaware
aware = naive.replace(tzinfo=tz.UTC)
AttributeError: module 'dateutil.tz' has no attribute 'UTC'
==============```
尝试使用 aws cli 从 AWS S3 复制文件时遇到类似问题。 运行 pip install python-dateutil
将 python-dateutil 更新为 2.8.1,现在运行良好。
python -m pip install --upgrade python-dateutil
升级python-dateutil
解决了我的问题。在我的机器上,2.5.3
到 2.8.1
。
略读源码,发现在2.7.0
中添加了UTC
变量。所以,我认为任何版本 >= 2.7.0
都可以解决问题。
#: Convenience constant providing a :class:`tzutc()` instance
#:
#: .. versionadded:: 2.7.0
UTC = tzutc()
尝试指定 python-dateutil 版本并将其安装在有错误的包之前,在您的情况下为 zappa 示例:
pip install python-dateutil==2.8.1 zappa
我的情况是我收到错误的包裹是 freezegun,所以我 运行
pip install python-dateutil==2.8.1 freezegun==0.3.15
成功了
我在尝试 运行 eb deploy
AWS Elastic Beanstalk 时遇到了这个问题。
对我有用的是: sudo pip3 install python-dateutil --upgrade
(注意:运行在没有 sudo 的情况下执行此操作无法解决问题)
作为参考,这是我在此之前遇到的错误:
eb deploy projectFoo
Deploying to development environment
Deploying to AWS
Creating application version archive "app-200711_113503".
Uploading projectFoo/app-200711_113503.zip to S3. This may take a while.
Upload Complete.
ERROR: AttributeError - module 'dateutil.tz' has no attribute 'UTC'