When executing the report on the web page to generate a word document, the following two errors occur:
1.ValueError: Invalid format string error
2.Python OSError: [Errno 22] Invalid argument:report name xxxx
Through the query, it is found that these two problems are caused by this sentence:
file_name = 'REPORTS_%s.docx'%time.strftime('%Y-%m-%d %H:%M:%s')
open with(file_name,'rb')as fp:
...
Solution to 1: if you want to change the small s in% s to the large s, you won’t report an error.
Solution to2: there is a problem in time acquisition. Colons cannot be used between hours, minutes and seconds!!!, Just separate them with an underline. Amend to read:
file_name = 'REPORTS_%s.docx'%time.strftime('%Y-%m-%d %H_%M_%S')
As for the solution of problem 2, I checked the relevant information and found that the following special characters [?*: “& lt; & gt;/|] cannot appear in the file name under windows. When using open with to read and write a file, the file name cannot be
Contains the above keywords. It can be solved by changing to other characters.
No error will be reported after the above problems are solved