Python Forum
[SOLVED] OSError: [Errno 22] Invalid argument
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[SOLVED] OSError: [Errno 22] Invalid argument
#11
Well, there is something in the filename that is not excepted in Windows. I don't remember what the allowed characters for filenames are. Perhaps the colons?

You have to change the datetime format.
For example. I don't use often the datetime module os I had to look ar the documentation
str(datetime.datetime.now().strftime('%Y-%m-%d %Hh%Mm%Ss'))
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply
#12
(Jun-03-2018, 02:39 PM)buran Wrote: the colon is not allowed in file name. Use something like
hdlr = logging.FileHandler('Path to the log file/Logs/log{}.log'.format(datetime.datetime.strftime(datetime.datetime.now(), '%Y%m%d%H%M%S_%f'))
Thank you. This fixed it
Self-taught HTML, CSS, Python, and Java programmer
Reply
#13
I would construct the filename on separate line
log_file = 'Path to the log file/Logs/log{}.log'.format(datetime.datetime.now().strftime('%Y%m%d%H%M%S_%f'))
hdlr = logging.FileHandler(log_file)
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#14
You cannot have colon sign as part of file name
Test everything in a Python shell (iPython, Azure Notebook, etc.)
  • Someone gave you an advice you liked? Test it - maybe the advice was actually bad.
  • Someone gave you an advice you think is bad? Test it before arguing - maybe it was good.
  • You posted a claim that something you did not test works? Be prepared to eat your hat.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  OSError occurs in Linux. anna17 2 192 Mar-23-2024, 10:00 PM
Last Post: snippsat
  Invalid argument: 'images\x08ackground.jpg' CatBall 4 905 Jun-19-2023, 09:28 AM
Last Post: CatBall
  OSError with SMPT script Milan 0 695 Apr-28-2023, 01:34 PM
Last Post: Milan
  OSERROR When mkdir Oshadha 4 1,660 Jun-29-2022, 08:50 AM
Last Post: DeaD_EyE
  [split] [Errno 22] Invalid argument Junaid 0 2,253 Jun-12-2021, 06:02 PM
Last Post: Junaid
  [solved] Variable number of dictionnaries as argument in def() paul18fr 11 6,026 Apr-20-2021, 11:15 AM
Last Post: paul18fr
  OSError: Unable to load libjvm when connecting to hdfs with pyarrow 3.0.0 aupres 0 3,101 Mar-22-2021, 10:25 AM
Last Post: aupres
  pyarrow throws oserror winerror 193 1 is not a valid win32 application aupres 2 3,734 Oct-21-2020, 01:04 AM
Last Post: aupres
  [Errno 22] Invalid argument satyaneel 11 105,803 Jul-14-2020, 08:47 AM
Last Post: lichunming
  zlib decompress error: invalid code lengths set / invalid block type DreamingInsanity 0 6,744 Mar-29-2020, 12:44 PM
Last Post: DreamingInsanity

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020