While investigating bug #1888037, I hit a traceback when swift served back corrupted headers:
vagrant@saio:~/swift$ swift stat 🌴 🌴
Traceback (most recent call last):
File "/usr/local/bin/swift", line 7, in <module>
exec(compile(f.read(), __file__, 'exec'))
File "/vagrant/python-swiftclient/bin/swift", line 24, in <module>
sys.exit(main())
File "/vagrant/python-swiftclient/swiftclient/shell.py", line 2059, in main
globals()['st_%s' % args[0]](parser, argv[1:], output)
File "/vagrant/python-swiftclient/swiftclient/shell.py", line 759, in st_stat
raise(stat_result["error"])
File "/vagrant/python-swiftclient/swiftclient/service.py", line 641, in _stat_object
items, headers = stat_object(conn, options, container, obj)
File "/vagrant/python-swiftclient/swiftclient/command_helpers.py", line 150, in stat_object
query_string=query_string)
File "/vagrant/python-swiftclient/swiftclient/client.py", line 1910, in head_object
query_string=query_string)
File "/vagrant/python-swiftclient/swiftclient/client.py", line 1802, in _retry
service_token=self.service_token, **kwargs)
File "/vagrant/python-swiftclient/swiftclient/client.py", line 1336, in head_object
resp_headers = resp_header_dict(resp)
File "/vagrant/python-swiftclient/swiftclient/client.py", line 796, in resp_header_dict
for header, value in resp.getheaders():
File "/vagrant/python-swiftclient/swiftclient/client.py", line 503, in getheaders
for k, v in self.resp.headers.items()]
File "/vagrant/python-swiftclient/swiftclient/client.py", line 503, in <listcomp>
for k, v in self.resp.headers.items()]
File "/vagrant/python-swiftclient/swiftclient/client.py", line 494, in _decode_header
return string.encode('iso-8859-1').decode('utf-8')
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x8e in position 1: invalid start byte
Of course, *there's corruption*, so it's hard for us to do much of anything *useful* -- but I was hoping that adding --debug would help me see what headers were causing issues. Nope; had to go use curl:
vagrant@saio:~/swift$ swift stat 🌴 🌴 --debug
DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): saio:443
DEBUG:urllib3.connectionpool:https://saio:443 "HEAD /v1/AUTH_test/%F0%9F%8C%B4/%F0%9F%8C%B4 HTTP/1.1" 200 0
DEBUG:swiftclient:REQ: curl -i https://saio/v1/AUTH_test/🌴/🌴 -I -H "X-Auth-Token: AUTH_tkb0683aed8c044d12a4e02a9f678dd2d9"
DEBUG:swiftclient:RESP STATUS: 200 OK
ERROR:swiftclient.service:'utf-8' codec can't decode byte 0x8e in position 1: invalid start byte
Traceback (most recent call last):
File "/vagrant/python-swiftclient/swiftclient/service.py", line 641, in _stat_object
items, headers = stat_object(conn, options, container, obj)
File "/vagrant/python-swiftclient/swiftclient/command_helpers.py", line 150, in stat_object
query_string=query_string)
File "/vagrant/python-swiftclient/swiftclient/client.py", line 1910, in head_object
query_string=query_string)
File "/vagrant/python-swiftclient/swiftclient/client.py", line 1802, in _retry
service_token=self.service_token, **kwargs)
File "/vagrant/python-swiftclient/swiftclient/client.py", line 1333, in head_object
{'headers': headers}, resp, body)
File "/vagrant/python-swiftclient/swiftclient/client.py", line 189, in http_log
log_method("RESP HEADERS: %s", scrub_headers(resp.getheaders()))
File "/vagrant/python-swiftclient/swiftclient/client.py", line 503, in getheaders
for k, v in self.resp.headers.items()]
File "/vagrant/python-swiftclient/swiftclient/client.py", line 503, in <listcomp>
for k, v in self.resp.headers.items()]
File "/vagrant/python-swiftclient/swiftclient/client.py", line 494, in _decode_header
return string.encode('iso-8859-1').decode('utf-8')
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x8e in position 1: invalid start byte
Traceback (most recent call last):
File "/usr/local/bin/swift", line 7, in <module>
exec(compile(f.read(), __file__, 'exec'))
File "/vagrant/python-swiftclient/bin/swift", line 24, in <module>
sys.exit(main())
File "/vagrant/python-swiftclient/swiftclient/shell.py", line 2059, in main
globals()['st_%s' % args[0]](parser, argv[1:], output)
File "/vagrant/python-swiftclient/swiftclient/shell.py", line 759, in st_stat
raise(stat_result["error"])
File "/vagrant/python-swiftclient/swiftclient/service.py", line 641, in _stat_object
items, headers = stat_object(conn, options, container, obj)
File "/vagrant/python-swiftclient/swiftclient/command_helpers.py", line 150, in stat_object
query_string=query_string)
File "/vagrant/python-swiftclient/swiftclient/client.py", line 1910, in head_object
query_string=query_string)
File "/vagrant/python-swiftclient/swiftclient/client.py", line 1802, in _retry
service_token=self.service_token, **kwargs)
File "/vagrant/python-swiftclient/swiftclient/client.py", line 1333, in head_object
{'headers': headers}, resp, body)
File "/vagrant/python-swiftclient/swiftclient/client.py", line 189, in http_log
log_method("RESP HEADERS: %s", scrub_headers(resp.getheaders()))
File "/vagrant/python-swiftclient/swiftclient/client.py", line 503, in getheaders
for k, v in self.resp.headers.items()]
File "/vagrant/python-swiftclient/swiftclient/client.py", line 503, in <listcomp>
for k, v in self.resp.headers.items()]
File "/vagrant/python-swiftclient/swiftclient/client.py", line 494, in _decode_header
return string.encode('iso-8859-1').decode('utf-8')
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x8e in position 1: invalid start byte
Pretty sure we can do better.