ValueError: Invalid timestamp "": Unknown string format
See original GitHub issuecode
for obj_sum in bucket.objects.all():
if obj_sum.storage_class == 'GLACIER':
obj = s3.Object(obj_sum.bucket_name, obj_sum.key)
if not obj.restore:
print('Submitting restoration request: %s' % obj.key)
obj.restore_object(RestoreRequest={"Days": 7})
stacktrace:
Traceback (most recent call last):
File "/Users/user/app/app-api/restore_s3.py", line 21, in <module>
temp_restore()
File "/Users/user/app/app-api/restore_s3.py", line 11, in temp_restore
if not obj.restore:
File "/Users/user/app/venv2/lib/python2.7/site-packages/boto3/resources/factory.py", line 339, in property_loader
self.load()
File "/Users/user/app/venv2/lib/python2.7/site-packages/boto3/resources/factory.py", line 505, in do_action
response = action(self, *args, **kwargs)
File "/Users/user/app/venv2/lib/python2.7/site-packages/boto3/resources/action.py", line 83, in __call__
response = getattr(parent.meta.client, operation_name)(**params)
File "/Users/user/app/venv2/lib/python2.7/site-packages/botocore/client.py", line 159, in _api_call
return self._make_api_call(operation_name, kwargs)
File "/Users/user/app/venv2/lib/python2.7/site-packages/botocore/client.py", line 483, in _make_api_call
operation_model, request_dict)
File "/Users/user/app/venv2/lib/python2.7/site-packages/botocore/endpoint.py", line 141, in make_request
return self._send_request(request_dict, operation_model)
File "/Users/user/app/venv2/lib/python2.7/site-packages/botocore/endpoint.py", line 168, in _send_request
request, operation_model, attempts)
File "/Users/user/app/venv2/lib/python2.7/site-packages/botocore/endpoint.py", line 233, in _get_response
response_dict, operation_model.output_shape)
File "/Users/user/app/venv2/lib/python2.7/site-packages/botocore/parsers.py", line 211, in parse
parsed = self._do_parse(response, shape)
File "/Users/user/app/venv2/lib/python2.7/site-packages/botocore/parsers.py", line 602, in _do_parse
member_shapes, final_parsed)
File "/Users/user/app/venv2/lib/python2.7/site-packages/botocore/parsers.py", line 658, in _parse_non_payload_attrs
member_shape, headers[header_name])
File "/Users/user/app/venv2/lib/python2.7/site-packages/botocore/parsers.py", line 258, in _parse_shape
return handler(shape, node)
File "/Users/user/app/venv2/lib/python2.7/site-packages/botocore/parsers.py", line 149, in _get_text_content
return func(self, shape, text)
File "/Users/user/app/venv2/lib/python2.7/site-packages/botocore/parsers.py", line 412, in _handle_timestamp
return self._timestamp_parser(text)
File "/Users/user/app/venv2/lib/python2.7/site-packages/botocore/utils.py", line 336, in parse_timestamp
raise ValueError('Invalid timestamp "%s": %s' % (value, e))
ValueError: Invalid timestamp "Thu,%2031%20Dec%202099%2020:00:00%20GMT": Unknown string format
tested on: python 2.7 and 3.5 python-dateutil==2.5.3 and python-dateutil==2.4.2 boto==2.39.0 and latest boto3 1.4.0
Issue Analytics
- State:
- Created 7 years ago
- Reactions:1
- Comments:18 (2 by maintainers)
Top Results From Across the Web
Pandas to_datetime ValueError: Unknown string format
I think the problem is in data - a problematic string exists. So you can try check length of the string in column...
Read more >Convert "unknown format" strings to datetime objects in Python
In this article, we are going to see how to convert the “Unknown Format” string to the DateTime object in Python.
Read more >[Code]-Unknown string format on pd.to_datetime-pandas
TypeError: Unrecognized value type: <class 'str'> ValueError: Unknown string format. The straight thing is that if I apply te function to a sample...
Read more >Need help passing date to pandas query - Python Forum
ValueError : ( 'Unknown string format:' , 'TestedDateBegin' ). During handling of the above exception, another exception occurred: ValueError Traceback (most ...
Read more >Source code for dateutil.tz.tz
timestamp = time.mktime((dt.year, dt.month, dt.day, dt.hour, # dt.minute, ... _parsetz(s) if res is None: raise ValueError("unknown string format") # Here ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Problem
Any un-parseable
Expires
header will mean you cannot retrieve the object withboto3
.Proposed Solution
In
botocore.parsers.ResponseParser
,_handle_timestamp
should returnNone
or, just the original text if it cannot be converted to datetime. (Possibly wrapped in custom type, ie,Unparseable(data)
)Or, the spec for “GetObjectResponse” should note a default value if “Expires” fails to parse.
Details
@kyleknap Here’s a reproduction from an internal issue we had with migrating from boto to boto3.
For some versions of
boto
, it would urlencode anyunicode
types passed inheaders
, resulting in objects that cannot be retrieved byboto3
.It’s not present in
2.45.0
, but I can confirm it is present inboto==2.38.0
with
boto==2.38.0
this printswith
boto==2.45.0
this printsThe result - objects affected by that bug cannot be read by
boto3
.I hit this issue after upgrading an unmaintained wagtail (which is django under the hood) site from an ancient version, which also meant migrating from boto to boto3.
All of the static files and media previously uploaded by boto had the same url-encoded value in the ‘Expires’ metadata:
This caused my
manage.py collectstatic
to fail when boto3.utils.parse_datetime() encountered that value.Building on the excellent workarounds suggested above, I came up with something slightly simpler:
I just call
patch_boto3_metadata_parsing()
at the top of my django settings/production.py and collectstatic now works 😃