虽然我通过"%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不会随机使用不同的硬编码字符串。 –