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
- Python oserror: [errno 22] invalid argument: emergence and solution
- Python: How to Batch Read the Form Information in Word and output them to Excel file
- [Solved] java.lang.IllegalStateException: Invalid host: lb://msg_provider
- Mac open terminal error – bash:: command not found
- JAVA: scanner Read File encoding Error noSuchElementException
- [Solved] Python Error: UnicodeDecodeError: ‘gb2312’ codec can’t decode byte 0xa4 in position… : illegal multibyte sequence
- [Solved] Dom4j parsing XML file error: invalid XML character (Unicode: 0x8)
- PIP install nltk Error: SyntaxError: invalid syntax (from nltk.tokenize import RegexpTokenizer)
- Python SyntaxError: unexpected character after line continuation character
- TypeError: write() argument must be str, not bytes