gpt4 book ai didi

amazon-dynamodb - Dynamodb create_table调用失败

转载 作者:行者123 更新时间:2023-12-04 11:35:03 34 4
gpt4 key购买 nike

我正在跟踪dynamodb的Python教程,以在端口8000上设置本地dynomodb
http://docs.aws.amazon.com/amazondynamodb/latest/gettingstartedguide/GettingStarted.Python.01.html

from __future__ import print_function # Python 2/3 compatibility
import boto3

dynamodb = boto3.resource('dynamodb', aws_access_key_id="anything", aws_secret_access_key="anything", region_name='us-west-2', endpoint_url="http://localhost:8000")


table = dynamodb.create_table(
TableName='users',
KeySchema=[
{
'AttributeName': 'username',
'KeyType': 'HASH'
},
{
'AttributeName': 'last_name',
'KeyType': 'RANGE'
}
],
AttributeDefinitions=[
{
'AttributeName': 'username',
'AttributeType': 'S'
},
{
'AttributeName': 'last_name',
'AttributeType': 'S'
},

],
ProvisionedThroughput={
'ReadCapacityUnits': 5,
'WriteCapacityUnits': 5
}

)
print("Table status:", table.table_status)

但是python运行代码失败并出现以下问题。

不知道是什么原因造成的。
Traceback (most recent call last):
File "C:\Users\rbharadw\workspace\dynamoDb\dynamoDb.py", line 32, in <module>
'WriteCapacityUnits': 5
File "Python\Python35\lib\site-packages\boto3\resources\factory.py", line 520, in do_action
response = action(self, *args, **kwargs)
File "Python\Python35\lib\site-packages\boto3\resources\action.py", line 83, in __call__
response = getattr(parent.meta.client, operation_name)(**params)
File "Python\Python35\lib\site-packages\botocore\client.py", line 159, in _api_call
return self._make_api_call(operation_name, kwargs)
File "Python\Python35\lib\site-packages\botocore\client.py", line 483, in _make_api_call
operation_model, request_dict)
File "Python\Python35\lib\site-packages\botocore\endpoint.py", line 117, in make_request
return self._send_request(request_dict, operation_model)
File "Python\Python35\lib\site-packages\botocore\endpoint.py", line 144, in _send_request
request, operation_model, attempts)
File "Python\Python35\lib\site-packages\botocore\endpoint.py", line 203, in _get_response
response_dict, operation_model.output_shape)
File "Python\Python35\lib\site-packages\botocore\parsers.py", line 211, in parse
parsed = self._do_parse(response, shape)
File "Python\Python35\lib\site-packages\botocore\parsers.py", line 587, in _do_parse
parsed = self._parse_shape(shape, original_parsed)
File "Python\Python35\lib\site-packages\botocore\parsers.py", line 258, in _parse_shape
return handler(shape, node)
File "Python\Python35\lib\site-packages\botocore\parsers.py", line 522, in _handle_structure
raw_value)
File "Python\Python35\lib\site-packages\botocore\parsers.py", line 258, in _parse_shape
return handler(shape, node)
File "Python\Python35\lib\site-packages\botocore\parsers.py", line 522, in _handle_structure
raw_value)
File "Python\Python35\lib\site-packages\botocore\parsers.py", line 258, in _parse_shape
return handler(shape, node)
File "Python\Python35\lib\site-packages\botocore\parsers.py", line 522, in _handle_structure
raw_value)
File "Python\Python35\lib\site-packages\botocore\parsers.py", line 258, in _parse_shape
return handler(shape, node)
File "Python\Python35\lib\site-packages\botocore\parsers.py", line 539, in _handle_timestamp
return self._timestamp_parser(value)
File "Python\Python35\lib\site-packages\botocore\utils.py", line 327, in parse_timestamp
return datetime.datetime.fromtimestamp(value, tzlocal())
File "Python\Python35\lib\site-packages\dateutil\tz\tz.py", line 99, in utcoffset
if self._isdst(dt):
File "Python\Python35\lib\site-packages\dateutil\tz\tz.py", line 143, in _isdst
return time.localtime(timestamp+time.timezone).tm_isdst
OSError: [Errno 22] Invalid argument

但是看起来像表被创建,因为第二次运行给出了错误
botocore.exceptions.ClientError: An error occurred (ResourceInUseException)  when calling the CreateTable operation: Cannot create preexisting table

有什么建议么!!!

最佳答案

不幸的是,设置os.environ [“TZ”] =“UTC”对我不起作用。

因此,我遵循一个线程,找到了site-packages\dateutil\tz\tz.py文件。在def _naive_is_dst(self,dt)函数中,将其更改为

   # workaround the bug of negative offset UTC prob
if timestamp+time.timezone < 0:
current_time = timestamp + time.timezone + 31536000
else:
current_time = timestamp + time.timezone

return time.localtime(current_time).tm_isdst

关于amazon-dynamodb - Dynamodb create_table调用失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38918668/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com