雖然我通過"%a %b %d %H:%M:%S %Z %Y"
作爲time.strptime()
中的格式字符串,但它在'%a %b %d %H:%M:%S %Y'
上運行,因此導致錯誤。任何想法可能會導致它?time.strptime()不遵守格式規定
同樣的事情在python控制檯中運行完美,但在實際的代碼中沒有。
Exception in thread Thread-7:
Traceback (most recent call last):
File "/usr/lib/python2.7/threading.py", line 801, in __bootstrap_inner
self.run()
File "/usr/lib/python2.7/threading.py", line 754, in run
self.__target(*self.__args, **self.__kwargs)
File "proxy.py", line 137, in listenThread
response = self.fetchRequest(raw_request, request)
File "proxy.py", line 114, in fetchRequest
if request['type'] == "GET" and self.is_cachable(request, response_headers):
File "proxy.py", line 100, in is_cachable
requestTime = time.mktime(time.strptime(self.request_log[request['url']][len(self.request_log[request['url']])-3]), "%a %b %d %H:%M:%S %Z %Y")
File "/usr/lib/python2.7/_strptime.py", line 478, in _strptime_time
return _strptime(data_string, format)[0]
File "/usr/lib/python2.7/_strptime.py", line 332, in _strptime
(data_string, format))
ValueError: time data 'Mon Apr 10 22:52:38 IST 2017' does not match format '%a %b %d %H:%M:%S %Y'
請顯示導致問題的實際代碼。 – DyZ
您在「Apr」和「10」之間獲得了額外的空間。 –
您必須運行的代碼不是您認爲的自己。 Python不會隨機使用不同的硬編碼字符串。 –