728x90
반응형

에러 메시지

>> OSError: [Errno 22] Invalid argument:
'C:\\{Location}\\venv\\Project_Management_excel\\Project_Management_excel_2020-08-07_21:56:14.xlsx'

1
2
3
4
5
6
7
8
9
10
11
12
Traceback (most recent call last):
  File "C:\{Location}/venv/Source/result_to_excel.py", line 145in <module>
    book.save(filename)
  File "C:\{Location}\venv\lib\site-packages\openpyxl\workbook\workbook.py", line 392in save
    save_workbook(self, filename)
  File "C:\{Location}\venv\lib\site-packages\openpyxl\writer\excel.py", line 291in save_workbook
    archive = ZipFile(filename, 'w', ZIP_DEFLATED, allowZip64=True)
  File "C:\{Location}\Programs\Python\Python37\lib\zipfile.py", line 1204in __init__
    self.fp = io.open(file, filemode)
 
OSError: [Errno 22] Invalid argument: 'C:\\{Location}\\Project_Management_excel_2020-08-07_21:56:14.xlsx'
 
cs

 

해결방법

 - 저장 경로나 파일명에 사용할 수 없는 특수문자 " : " 를 사용했기 때문에 발생

 

 - 파일 경로에 :, /, \, *, ?, <, | 등은 사용 불가

 

 - 문제 발생 코드

1
2
3
4
import time
 
nowstring = "%04d-%02d-%02d_%02d:%02d:%02d" % (now.tm_year, now.tm_mon, now.tm_mday, now.tm_hour, now.tm_min, now.tm_sec)
filename = "C:\\{Location}\\Project_Management_excel_%19s.xlsx" % nowstring
cs

 

 - 변경 및 해결 완료 코드

1
2
3
4
import time
 
nowstring = "%04d-%02d-%02d_%02d-%02d-%02d" % (now.tm_year, now.tm_mon, now.tm_mday, now.tm_hour, now.tm_min, now.tm_sec)
filename = "C:\\{Location}\\Project_Management_excel_%19s.xlsx" % nowstring
cs

 

728x90
반응형

+ Recent posts